Skip to content

Instantly share code, notes, and snippets.

@jaxxreal
Last active August 29, 2015 14:05
Show Gist options
  • Save jaxxreal/f288f60bde3bb08e88f1 to your computer and use it in GitHub Desktop.
Save jaxxreal/f288f60bde3bb08e88f1 to your computer and use it in GitHub Desktop.
simple script loader
var loadScript = function (resources, callback) {
var
getScript = function (path) {
var s = document.createElement('script');
s.setAttribute('src', path);
s.onload = handler;
document.body.appendChild(s);
console.log(path + " loaded");
},
length = resources.length,
handler = function () { counter++; },
counter = 0,
checker;
for (var i = 0; i < length; i++) {
getScript(resources[i]);
}
checker = setInterval(function () {
if (counter === length) {
callback();
clearInterval(checker);
}
}, 100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment