Skip to content

Instantly share code, notes, and snippets.

@tlightsky
Created May 5, 2015 08:43
Show Gist options
  • Save tlightsky/c7e5342699b65aa91cb7 to your computer and use it in GitHub Desktop.
Save tlightsky/c7e5342699b65aa91cb7 to your computer and use it in GitHub Desktop.
load js by sequence
scripts.push("js/index.js");
scripts.push("js/txt.js");
function load_js (scripts) {
var scriptsEle = [];
var h = document.getElementsByTagName('head')[0];
scripts.forEach(function (val, index) {
var js = document.createElement('script');
js.type = "text/javascript";
h.appendChild(js);
scriptsEle[index] = js;
if(index > 0) {
scriptsEle[index-1].onload = function () {
js.src = val;
}
}
});
scriptsEle[0].src = scripts[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment