Skip to content

Instantly share code, notes, and snippets.

@AWaselnuk
Created November 19, 2014 16:32
Show Gist options
  • Save AWaselnuk/49f2547058f47950b600 to your computer and use it in GitHub Desktop.
Save AWaselnuk/49f2547058f47950b600 to your computer and use it in GitHub Desktop.
Load external javascript files asynchronously
//this function will work cross-browser for loading scripts asynchronously
//from: http://stackoverflow.com/questions/7718935/load-scripts-asynchronously
function loadScript(src, callback)
{
var s,t,done;
done = false;
s = document.createElement('script');
s.type = 'text/javascript';
s.src = src;
s.onload = s.onreadystatechange = function() {
//console.log( this.readyState ); //uncomment this line to see which ready states are called.
if ( !done && (!this.readyState || this.readyState == 'complete') )
{
done = true;
callback();
}
};
t = document.getElementsByTagName('script')[0];
t.parentNode.insertBefore(s, t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment