Skip to content

Instantly share code, notes, and snippets.

@iamnewton
Created January 13, 2014 02:05
Show Gist options
  • Save iamnewton/8393529 to your computer and use it in GitHub Desktop.
Save iamnewton/8393529 to your computer and use it in GitHub Desktop.
Google's recommended way to defer a script. Just insert the path to the file and place at the bottom of the page just before the <body>.
var createScript = function() {
var script = document.createElement( "script" );
script.src = "path/to/file.js";
document.body.appendChild( script );
};
if ( window.addEventListener ) {
window.addEventListener( "load", createScript, false );
} else {
if ( window.attachEvent ) {
window.attachEvent( "onload", createScript );
} else {
window.onload = createScript;
}
}
@iamnewton
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment