Created
June 7, 2014 08:13
-
-
Save esedic/7a95ac4680bc550747f8 to your computer and use it in GitHub Desktop.
Defer javascript - Google way
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
<!-- Put this before </body> tag --> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment