Created
January 2, 2014 14:20
-
-
Save botaor/8219782 to your computer and use it in GitHub Desktop.
Defer loading of Javascript files untill the page is already loaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
function downloadJSAtOnload() { | |
var element = document.createElement("script"); | |
element.src = "defer.js"; | |
document.body.appendChild(element); | |
} | |
if (window.addEventListener) | |
window.addEventListener("load", downloadJSAtOnload, false); | |
else if (window.attachEvent) | |
window.attachEvent("onload", downloadJSAtOnload); | |
else | |
window.onload = downloadJSAtOnload; | |
</script> | |
/* | |
This was taken from: | |
http://www.feedthebot.com/pagespeed/defer-loading-javascript.html | |
Also have a look at the following URLs | |
http://ablogaboutcode.com/2011/06/14/how-javascript-loading-works-domcontentloaded-and-onload/ | |
http://www.feedthebot.com/pagespeed/critical-render-path.html | |
http://vimeo.com/71362583 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment