Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Created February 22, 2011 13:25
Show Gist options
  • Save phiggins42/838658 to your computer and use it in GitHub Desktop.
Save phiggins42/838658 to your computer and use it in GitHub Desktop.
function addScript(src){
var script = document.createElement("script");
script.src = src;
script.onload = script.onreadystatechange = function(e){
if(e && e.type == "load" || /loaded|complete/.test(script.readyState)){
script.onload = script.onreadystatechange = null;
console.log("foo.js added and ready");
}
}
return (document.head || document.getElementsByTagName("head")[0]).appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment