Permalink
Browse files

Load scripts in order

  • Loading branch information...
1 parent fcd6503 commit 98dc4441a862aabbf23bd36177c4046641c44914 @copy committed Sep 14, 2015
Showing with 21 additions and 6 deletions.
  1. +21 −6 loader.js
View
@@ -14,14 +14,15 @@
// jor1k stuff
LIB_FILES += " jor1k.js 9p.js filesystem.js marshall.js utf8.js";
+ var to_load = [];
+
load_scripts(CORE_FILES, "src/");
load_scripts(BROWSER_FILES, "src/browser/");
load_scripts(LIB_FILES, "lib/");
function load_scripts(resp, path)
{
- var files = resp.split(" "),
- script;
+ var files = resp.split(" ");
for(var i = 0; i < files.length; i++)
{
@@ -30,10 +31,24 @@
continue;
}
- script = document.createElement("script");
- script.src = path + files[i] + "?" + Math.random();
- script.defer = "defer";
- document.head.appendChild(script);
+ to_load.push(path + files[i]);
}
}
+
+ load_next();
+
+ function load_next()
+ {
+ var s = to_load.shift();
+
+ if(!s)
+ {
+ return;
+ }
+
+ var script = document.createElement("script");
+ script.src = s;
+ script.onload = load_next;
+ document.head.appendChild(script);
+ }
})();

0 comments on commit 98dc444

Please sign in to comment.