Created
December 9, 2012 19:53
-
-
Save greypants/4246724 to your computer and use it in GitHub Desktop.
PageSpeed defer javascript example
This file contains 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> | |
// Add a script element as a child of the body | |
function downloadJSAtOnload() { | |
var element = document.createElement("script"); | |
element.src = "deferredfunctions.js"; | |
document.body.appendChild(element); | |
} | |
// 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; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment