Created
August 26, 2016 19:50
-
-
Save asciimo/fd694b71a93af5d17cbc176ddbda8c42 to your computer and use it in GitHub Desktop.
"Unobtrusive lazy load pattern" from [friendlybit.com](https://friendlybit.com/js/lazy-loading-asyncronous-javascript/).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
function async_load(){ | |
var s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; | |
s.src = 'http://yourdomain.com/script.js'; | |
var x = document.getElementsByTagName('script')[0]; | |
x.parentNode.insertBefore(s, x); | |
} | |
if (window.attachEvent) | |
window.attachEvent('onload', async_load); | |
else | |
window.addEventListener('load', async_load, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment