Login Register

Module Helpers

Modules for Non-JavaScript Resources

dojo.require() works fine for JavaScript, but what about images, CSS, and other resources? Do you need to access them through absolute paths? Fortunately no. The following code:

var imgNode = document.createElement("img");
imgNode.src = dojo.moduleUrl("explosive.space","images/kaboom.gif");
locates the kaboom.gif file in our module. The nice thing is ... this code will work in any page that has registered the module. It doesn't matter where the code snippet is located relative to kaboom.gif. Slick!

Conditional Inclusion

Sometime modules are dojo.require'd because they may be used. If they are not used, that's a small bit of wasted time. If you know at runtime whether modules need inclusion, you can use dojo.requireIf:

dojo.requireIf(dojo.isIE, "explosive.space.BlueScreenOfDeathCatcher");