Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created July 26, 2012 04:20
Show Gist options
  • Save orangexception/3180235 to your computer and use it in GitHub Desktop.
Save orangexception/3180235 to your computer and use it in GitHub Desktop.
// A better way to load your JavaScript. I've shared this on Google+ before. Emil Stenstr?m created the script and explains everything on his post, (Lazy Loading Asynchronous JavaScript)[http://friendlybit.com/js/lazy-loading-asyncronous-javascript/]
<script type= "text/javascript">
(function() {
function async_load() {
var s= document.createElement('script');
s.type= 'text/javascript';
s.async= true;
s.src= 'http://c322385.r85.cf1.rackcdn.com/application.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 );
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment