Dojo.require() is your friend

One of the cool parts of Dojo is the ability to only load the modules and widgets your page needs. This is done with the dojo.require() method. Wherever your script is you can call dojo.require() and the module will be loaded in real time. The follow is an example of some script blocks that may be in the page header of an HTML page:


Dojo.require() does a lot of work for you. For instance it will not load the modules more than once and will load all dependent modules for you. One thing you will read in the help is the combination of using dojo.require() with dojo.addOnLoad(). This insures the module is loaded before you continue executing any relying code. So it is a best practice to chain these calls together when calling require() dynamically.

      // dijit.Dialog and friends are ready, create one from a node with id="bar"
      var dialog = new dijit.Dialog({ title:"Lazy Loaded" }, "bar");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.