R – DOJO include script from CDN

dojofirefox

Currently I'm trying to include Dojo from either one of these two CDN (Content Delivery Network) sources:

1) o.aolcdn.com/dojo/1.3.2/dojo/dojo.xd.js

2) ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js

It seems like some times during the day, Firefox 3.5 refuses to load the dojo library.
I see errors in Firebug console like "dojo is not defined" when I do a "dojo.require" statement. Also from Firebug and go to the "Net" tab, and see no history of any attempt to load from the above dojo libs.

Yet, I can open the same page in IE7 and it works. I have flushed cache in FireFox, and killed and re-opened it (but I was using the restore previous pages option).

One time today, when I switched from AOL 1.3.2 to 1.1 it worked once, then never has worked again.

Thanks,
Neal

Best Answer

Sounds like timing issues. Are you sure you do CDN right? The trick is you cannot use what's defined in files you dojo.require()d right away — they are going to be loaded asynchronously.

The basic structure of the CDN-based application is like this:

<script src="to/dojo/cdn"></script>
<script>
  dojo.require("dojo.this");
  dojo.require("dojo.that");
  // more dojo.require()
  // you cannot use dojo.this and dojo.that here
  dojo.addOnLoad(function(){
    // this is crucial: do everything in dojo.addOnLoad();
    // now use dojo.this and dojo.that
    dojo.this(dojo.that);
  });
</script>

In order to troubleshoot you can do one thing: write a minimal web page, which loads Dojo using your favorite CDN and does nothing. Open it up in Firefox, open Firebug and enter some simple Dojo calls manually to see if it works for you. If it doesn't, switch to the Net tab and see what calls were made, when, and how they ended.

Related Topic