Skip to content

Instantly share code, notes, and snippets.

@hsubra89
Created August 11, 2014 04:10
Show Gist options
  • Save hsubra89/4faff3eb9b2c7b22604a to your computer and use it in GitHub Desktop.
Save hsubra89/4faff3eb9b2c7b22604a to your computer and use it in GitHub Desktop.
async adding javascript
var addScript = function(url,success){
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0], done=false;
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done=true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment