Datasheet
Chapter 1: Enhancing Development with Dojo Core
means that Dojo will orient itself with respect to relative paths from wherever you’ve installed Dojo and
its subprojects — which could mean the AOL CDN, if you chose to go that route.
Thus, consider that a
dojo.require("decafbad.util.foo")
might resolve to the following:
http://o.aolcdn.com/dojo/1.1.1/decafbad/foo/bar.xd.js
It’s highly unlikely that you can host your project on the AOL CDN, so you’ll want Dojo to look for your
code elsewhere. And, even if you’re using a locally downloaded installation of Dojo, it’s cleaner to keep
your code out of that directory in case you plan on ever upgrading Dojo in the future. So, here’s where
dojo.registerModulePath()
comes in:
dojo.registerModulePath(‘decafbad’, ‘../../ex-dojo-core/decafbad’);
If you’re using a local installation of Dojo, this statement will cause any
dojo.require()
call for
decafbad
or any of its child modules to be loaded from the given path relative to the
dojo
module directory. For
example, consider this as a directory structure for your project:
❑
dojodev
❑
dojo/dojo.js
❑
ex-dojo-core/
❑
hello.html
❑
decafbad/foo/bar.js
Because
dojo.js
resides under the
dojodev/dojo/
directory, the registered relative module path
../../ex-dojo-core/decafbad
would be found outside the Dojo installation itself.
Where things get a little trickier is if you’re using the AOL CDN version of Dojo, which is an XDomain
build. That means this particular build of Dojo is geared toward loading its resources from a different
domain (that is,
o.aolcdn.com
) versus where it’s been included (that is, yours). Because of the particulars
of implementation of cross-domain module loading, the situation is slightly different than what a local
Dojo install allows.
For the most part, you don’t need to worry too much about what this implies — but in this case, it means
you need to include a base URL for your modules, relative to the current page instead of a local Dojo
installation, in
djConfig
:
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"
djConfig="isDebug: true, parseOnLoad: true, baseUrl: ‘./’"></script>
<script type="text/javascript">
dojo.registerModulePath(‘decafbad’, ‘./decafbad’);
dojo.require("dojo.parser");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("decafbad.foo.bar");
</script>
10