dojo.required Reading: It Ain’t Loaded ‘Til It’s Loaded

August 23, 2010 by Ken · 8 Comments 

One of the most fundamental yet powerful features of the Dojo Toolkit is its module and dependency management system, harnessed via dojo.require. I’ve seen one important detail elude countless developers, however: the distinction between when a module is dojo.required, and when it is actually loaded and ready for use. It’s very easy to mishandle this, and the nature in which it tends to come back to bite leaves no indication of the actual problem to the unwary developer. This usually crops up in the form of the following question:

  • I’ve dojo.required widget X using cross-domain Dojo, but when I go to instantiate X, I get an exception saying that X is not a constructor!

Depending upon what module was requested, the exception might instead say SomeNamespaceAboveX is undefined.

Interestingly, both the API and Reference Guide pages for dojo.require actually sort of answer this question (or rather, show how to avoid encountering it completely), but in this post I aim to clarify why this happens (and perhaps encourage a few wandering souls to read the docs more often).

Read more