Skip to content

Instantly share code, notes, and snippets.

@hotchpotch
Created November 6, 2009 02:39
Show Gist options
  • Save hotchpotch/227642 to your computer and use it in GitHub Desktop.
Save hotchpotch/227642 to your computer and use it in GitHub Desktop.
__jsloader__ = function(scripts, callback, errorback) {
var now = (new Date()) - 0;
if (typeof errorback != 'function')
errorback = function(url) { alert('jsloader load error: ' + url) };
var load = function(url) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.charset = 'utf-8';
var current_callback;
if (scripts.length) {
var u = scripts.shift();
current_callback = function() { load(u) }
} else {
current_callback = callback;
}
if (window.ActiveXObject) { // IE
script.onreadystatechange = function() {
if (script.readyState == 'complete' || script.readyState == 'loaded')
current_callback();
}
} else {
script.onload = current_callback;
script.onerror = function() { errorback(url) };
}
script.src = url + '?' + now;
document.body.appendChild(script);
}
load(scripts.shift());
}
//window.onload = function() {
// __jsloader__(['a.js', 'b.js'], function() { alert('loaded') });
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment