Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/50b07ee690bcd01ff07a to your computer and use it in GitHub Desktop.
Save andreasvirkus/50b07ee690bcd01ff07a to your computer and use it in GitHub Desktop.
// add this as the only script before your closing body tag
// and let it load your external scripts once your DOM has finished loading.
function addJSOnload() {
var element = document.createElement("script");
element.src = "defer.js"; // replace your script with "defer.js"
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", addJSOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", addJSOnload);
else
window.onload = addJSOnload;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment