Hi,
I am trying out the xDomain usage, but have run into the issue where dojo loads fine, but dojo.require() calls to load my local modules are failing. On firfox, the console shows that the corresponding GET requests have succeeded (with the proper content of the files in the response body), but dojo throws up a message saying it could not load the XDomain resource, with the correct URL for it. I know that there are no syntax errors etc in my modules since they load fine with a local build of dojo. Am I missing something obvious here? My header looks as follows:
<!--
var deployed = false, djConfig = {
isDebug: !deployed,
parseOnLoad: false,
locale: "en",
modulePaths: {
"lipik": deployed ? "/scripts/lipik/release" : "/scripts/lipik/debug",
"lipik.Locale.layouts": "/scripts/lipik/layout-defs"
},
useXDomain: true,
baseUrl: "/."
};
delete deployed;
-->
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dojo/dojo.xd.js"></script>
<script type="text/javascript">
<!--
dojo.require("lipik.Foundation");
dojo.addOnLoad(function() {
// some stuff here
});
-->
</script>
I am hoping to be able to use google's load() api to load dojo. Btw, if I do use it, is there a way to remove the eplicit css includes ('@import dojo.css'), but load them from inside onLoad handler, so dojo location or version is never hardcoded?
Thanks
Amit

djConfig.baseUrl should end
djConfig.baseUrl should end in a slash, so maybe the value should be "./" maybe that is just a typo.
If you use djConfig.debugAtAllCosts = true, does that give any more information, a possible script error?
Here is an example of loading local modules with a CDN dojo. You can download the full example here:
http://jburke.dojotoolkit.org/demos/xdlocal/xdlocal.zip
If that does not help, it would be good to try a test URL to debug further. You can contact me off-list at jburke at dojotoolkit dot org.
Initially there were issues with google.load interfering with the dojo loading process. I do not think that has been resolved, and unfortunately I forgot the issue. I think that you may need to use the djConfig.afterOnLoad path to dojo if loading via google.load. You can try it, but I would not be surprised if it has an issue.
On the CSS pathing, you might be able to do something in script where you do:
var doc = dojo.doc;
var element = doc.createElement("link");
element.type = "text/css";
element.rel = "stylesheet";
element.href = dojo.moduleUrl("dijit", "themes/tundra/tundra.css");
doc.getElementsByTagName("head")[0].appendChild(element);
});
The downside with this approach is that your page will initially show unstyled, then have the style pop in later.
A clue!
Hi,
I had looked at xdLocal before, and as far as I can tell, I am following the same pattern.
debugAtAllCosts does not help. My local module has this form:
dojo.provide("lipik.Foundation"); dojo.require("dojo.cookie"); var lipik = { Foundation: {} };Funny thing is none of them have a problem when loading locally, and all of them do when loading XDomain. I put in a breakpoint inside the and it shows me that the following call is being made (stack is _loadUri()->(?)()->eval()):
dojo._xdResourceLoaded(function(){ 2return {depends: [["provide", "lipik.Foundation"], 3["require", "dojo.cookie"], 4["require", moduleName], 5["require", "dojo.cookie"]], 6defineResource: function(){ 7}, resourceName: 'lipik.Foundation', resourcePath: '/scripts/lipik/debug/Foundation.js'};});The problem is that
moduleNameis not defined and it falls over. Also, is it expected that dojo.cooke should appear twice in the array?My HTML file has a:
dojo.require("lipik.Foundation");and Foundation.js has:
dojo.provide("lipik.Foundation"); dojo.require("dojo.cookie");And I have just realized, there is a require(moduleName) statement in my code. It appears like so:
var lipik = { loadModule: function(moduleName) { dojo.require(moduleName); if (typeof(dojo.getObject(moduleName)) == 'undefined') { dojo.publish(lipik.ETopics.asyncLoadStart, [moduleName]); dojo.addOnLoad(function() { dojo.publish(lipik.ETopics.asyncLoadEnd, [moduleName]) }); } } ...Is this not allowed? I was assuming it would only be evaluated when that function runs. Maybe I was wrong and dojo's loading mechanism does not execute require() calls, but does some sort of search/replace on them?
Thanks for the tip regarding CSS. Guess I could also use dojox.style api's to create style nodes dynamically.
Amit
Some comments: 1) The code
Some comments:
1) The code you give for your module:
dojo.require("dojo.cookie");
var lipik = {
Foundation: {}
};
The var lipik is not needed since dojo.provide automatically creates the lipik and lipik.Foundation modules. And by using the var lipik, you could be shadowing the real definition of lipik.Foundation. So I suggest not doing the var lipik assignment: dojo.provide will have already created the empty objects for you.
2) For the dojo.require(moduleName) thing, write is like so:
The build system and xd loader use regexps to find dojo.require calls to load dependencies, and they are not smart enough to process variable names, so that will cause problems. There is a bug logged to allow this, but in the meantime, using the dojo["require"] syntax avoids the issue.
Thank you!
It works with these changes.
I am able to use google.load, with djConfig.afterOnLoad: true and djConfig.addOnLoad instead of dojo.addOnLoad. One thing I discovered, which might save other readers some time, is that google.load("dojo", "1") only load 1.1.1 by default, which does not support these mechanisms. I guess google's links have not been updated yet. It is necessary to specify google.load("dojo", "1.2") explicitly.
Now all I need to do is to write a script dynamically to pull in CSS from dojo's URL...
Thanks a lot for the help.
that is a very interesting
that is a very interesting observation. I've not tried to use google.load() before to include the script, but using djConfig params for afterOnLoad, require, and addOnLoad makes sense as to why it would work (dojo.js internally handles all those things, and only fires when dojo is ready).
Last I heard from google, they were waiting on us to announce official 1.2 support before updating their aliases for "1" to "1.2" - it should be done very soon, as we announced yesterday.
Regards,
Peter Higgins
Sample code to load CSS
Hi,
I did write the function to load framework CSS. Sharing the code here, in case it might help someone else:
(Tested on FF3 & IE7 so far)
var e1 = dojo.doc.createElement("link"), e2, head;
e1.type = "text/css";
e1.rel = "stylesheet";
e1.href = dojo.moduleUrl("dojo", "resources/dojo.css");
var head = dojo.doc.getElementsByTagName("head")[0];
e2 = dojo.query("style", head); // we'll try to add the CSS before any possible user overrides
e1 = e2.length ? head.insertBefore(e1, e2[0]) : head.appendChild(e1);
if (dijitTheme) {
e2 = e1.cloneNode(true);
e2.href = dojo.moduleUrl("dijit", String("themes/dijitTheme/dijitTheme.css").replace(/dijitTheme/g, dijitTheme));
if (e2.href) { // in case the caller misspelt the theme or something? Hopefully dojo.moduleUrl would fail then
dojo.addClass(dojo.body(), dijitTheme);
head.insertBefore(e2, e1);
}
}
},
Thanks,
Amit
google.load() wont work when loading dojo after page load.
I ran into the same problem trying to load dojo using google.load() after the page is loaded. After digging into the compiled code at http://www.google.com/jsapi - it looks like they are actually using document.write() to write the script tags. Yikes!
Worked around it with following code. Just want to post of anyone struggling with the same..
djConfig = {
isDebug: true,
afterOnLoad: true,
parseOnLoad: true,
baseUrl: "./"
}
function loadDojo() {
//google.load("dojo","1.2.0");
var node = document.createElement("script");
node.type = "text/javascript";
node.src = google.loader.GoogleApisBase
+"/libs/dojo/1.2.0/dojo/dojo.xd.js";
document.getElementsByTagName("head")[0].appendChild(node);
}
if(window.addEventListener){
window.addEventListener("load", loadDojo, false);
}else{
window.attachEvent("onload", loadDojo);
}