I made a very simple example (adapted from my real project) that uses LABjs (v2.0.3) to load the javascript files and execute them in a given order. I'm pasting the code below.
- Since testLAB.js waits for mainCanvas.js, who waits for events.js, I expect the order of the alerts to be: "events.js" "mainCanvas.js" "testLAB.js".
- However, I get usually either the reversed order: "testLAB.js" "mainCanvas.js" "events.js".
- Sometimes I get "testLAB.js" "events.js" "mainCanvas.js".
Can anybody explain?
The full example can be downloaded here.
EDIT: I'm using node.js and the http-server module to serve these pages locally (in case you want to try it out locally as well)
file: index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test lab.js</title>
<script src="js/lib/LAB.js"></script>
<script src="js/app/testLAB.js"></script>
</head>
<body>
</body>
</html>
file: js/app/testLAB.js
$LAB.setGlobalDefaults({
BasePath: "/js/",
Debug:true
});
$LAB
.script("lib/underscore.min.js")
.script("app/mainCanvas.js").wait(function(){
alert("testLAB.js");
});
file: js/app/mainCanvas.js
$LAB
.script("lib/jquery.js").wait()
.script("lib/underscore.min.js")
.script("app/events.js")
.wait(function() {
alert("mainCanvas.js");
});
file: js/app/events.js
$LAB
.script("lib/jquery.js")
.script("lib/underscore.min.js")
.wait(function() {
alert("events.js");
});