Skip to content

Instantly share code, notes, and snippets.

@qmmr
Created January 31, 2013 20:01
Show Gist options
  • Save qmmr/4685913 to your computer and use it in GitHub Desktop.
Save qmmr/4685913 to your computer and use it in GitHub Desktop.
loadScript function - async
var loadScript = function(url, callback) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
if (s.readyState) { // Internet Explorer
s.onreadystatechange = function() {
if (s.readyState == 'loded' || s.readyState == 'complete') {
s.onreadystatechange = null;
callback();
}
};
}
else { // other browsers
s.onload = function() {
callback();
};
}
s.src = url;
document.getElementsByTagName('head')[0].appendChild(s);
};
loadScript("https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js", function() {
alert('jQuery loaded!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment