Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Forked from brandonb927/gist:4580977
Last active December 15, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save james2doyle/5307382 to your computer and use it in GitHub Desktop.
Save james2doyle/5307382 to your computer and use it in GitHub Desktop.
JS lazyloading that is non-blocking, shamefully stolen from http://friendlybit.com/js/lazy-loading-asyncronous-javascript/
(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