Skip to content

Instantly share code, notes, and snippets.

@rsoury
Created December 5, 2017 01:15
Show Gist options
  • Save rsoury/85f8607a2c750490e64bb61d0e2f5316 to your computer and use it in GitHub Desktop.
Save rsoury/85f8607a2c750490e64bb61d0e2f5316 to your computer and use it in GitHub Desktop.
Async JS Lib Load
(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