Testing synchronous vs asynchronous Dojo 1.9
I have this in a.js:
require(["dojo/_base/xhr"], function(){
console.log("a");
});
I have this in b.js:
define(["dojo/_base/xhr"], function(){
console.log("b");
return {};
});
And I run this (in index.html):
console.log("TESTING Part One");
require([ "a" ], function() {
console.log("c");
});
console.log("TESTING Part Two");
require([ "b" ], function() {
console.log("c");
});
Output 1 - Asynchronous: here is my output with data-dojo-config="async: true"
TESTING Part One
TESTING Part Two
a
c
c
b
Output 2 - Synchronous: here is my output with data-dojo-config=""
TESTING Part One
a
c
TESTING Part Two
b
c
- With output 1, why are the "TESTING Part .." strings being output first?
- Is it because the two requires in index.html are creating anonymous blocks of code that are being asynchronously?
- Is this sneaky way of spinning off threads?
- With output 1, why is "b" even being output at all?
- From here: http://livedocs.dojotoolkit.
org/loader/amd#the-amd-api: "Module creation is lazy and asynchronous, and does not occur immediately when define is called. This means that factory is not executed, and any dependencies of the module will not be resolved, until some running code actually requires the module." - Nothing is actually calling on "b", so why is it executed at all?
- With output 2, does this mean that synchronous config turns off this AMD feature: "Module creation is lazy and asynchronous"?