Created
December 5, 2017 01:15
-
-
Save rsoury/85f8607a2c750490e64bb61d0e2f5316 to your computer and use it in GitHub Desktop.
Async JS Lib Load
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
(function(window, document){ | |
var load = function(){ | |
var script = document.createElement('script'); | |
script.async = true; | |
script.type = 'text/javascript'; | |
script.src = 'THE_SOURCE_OF_JS_LIB_HERE.js'; | |
var firstScript = document.getElementsByTagName('script')[0]; | |
firstScript.parentNode.insertBefore(script, firstScript); | |
}; | |
if(document.readyState === "complete"){ | |
load(); | |
}else if(window.attachEvent){ | |
window.attachEvent('onload', load); | |
}else{ | |
window.addEventListener('load', load); | |
} | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment