Created
November 19, 2014 16:32
-
-
Save AWaselnuk/49f2547058f47950b600 to your computer and use it in GitHub Desktop.
Load external javascript files asynchronously
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
//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