Skip to content

Instantly share code, notes, and snippets.

@bantya
Created June 18, 2016 11:48
Show Gist options
  • Select an option

  • Save bantya/86f6221a3a872e0141b4ca239cb3e05e to your computer and use it in GitHub Desktop.

Select an option

Save bantya/86f6221a3a872e0141b4ca239cb3e05e to your computer and use it in GitHub Desktop.
JavaScript: loadScripts
// Loads js files
function loadScripts(urlArray,cb) {
var scriptLoadCount = scriptLoadedCount = 0;
loadScript();
function loadScript() {
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
var url = (urlArray[scriptLoadCount].indexOf('?') == -1) ? urlArray[scriptLoadCount] + '?d=' + Math.random() : urlArray[scriptLoadCount] + '&d=' + Math.random()
script.src= url;
head.appendChild(script);
scriptLoadCount++;
script.onload = function() {
scriptLoadedCount++;
if (scriptLoadedCount < urlArray.length) loadScript();
else if (cb) cb();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment