Created
February 28, 2013 20:58
-
-
Save chrisblackwell/5060068 to your computer and use it in GitHub Desktop.
Lazyly Load JavaScript
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> | |
function lazyLoadJavaScript() { | |
var scripts = document.createElement("script"), | |
jquery = document.createElement("script"); | |
scripts.src = "{{ source to your custom scripts }}"; | |
jquery.src = "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"; | |
document.body.appendChild(jquery); | |
document.body.appendChild(scripts); | |
} | |
if (window.addEventListener) | |
window.addEventListener("load", lazyLoadJavaScript, false); | |
else if (window.attachEvent) | |
window.attachEvent("onload", lazyLoadJavaScript); | |
else window.onload = lazyLoadJavaScript; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment