Skip to content

Instantly share code, notes, and snippets.

@skatebkp
Created May 15, 2013 07:49
Show Gist options
  • Select an option

  • Save skatebkp/5582271 to your computer and use it in GitHub Desktop.

Select an option

Save skatebkp/5582271 to your computer and use it in GitHub Desktop.
5. Defer loading of JavaScript If you must use JavaScript, then it is a good idea to defer the loading of this code until after the page load event has fired. Google actually provides a deferral script you can use to do this: codesource // Add a script element as a child of the body function downloadJSAtOnload() { var element = document.createEl…
// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment