Why are so many dojo modules pulled in?

1253
16
11-15-2011 11:08 AM
RexBradford
New Contributor II
I'm wondering if it's possible to reduce the number of unused and unwanted dojo modules being pulled in, to help reduce app load time.

I am explicitly requiring only these 11 modules:

dojo.require("esri.map");
dojo.require("esri.layers.osm");
dojo.require("esri.virtualearth.VEGeocoder");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.layers.KMLLayer");
dojo.require("esri.dijit.Scalebar");
dojo.require("esri.toolbars.navigation");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.Dialog");
dojo.require("dojox.collections.Dictionary");

so these entries in Firebug's net window are hardly surprising, except maybe the first:

firebug.xd.js
svg.xd.js
jsapi_en-us.xd.js
osm.xd.js
KMLLayer.xd.js
FeatureLayer.xd.js
Scalebar.xd.js
BorderContainer.xd.js
Dialog.xd.js
ContentPane.xd.js
Dictionary.xd.js.

but then look at what keeps coming after those (.xd.js file extensions removed to save room):

iframe, MapImageLayer, Popup, _LayoutWidget, cookie, _ContentPanelResizeMixin, html, loading, TimedMoveable, _FormMixin, DialogUnderlay, _DialogMixin, common, TooltipDialog, PopupBase, Chart2D, base, Tooltip, _Contained, Default, Default (twice!), Invisible, Lines, Areas, MarkersOnly, Markers, Scatter, StackedAreas, StackedLines, Columns, StackedColumns, Bars, ClusteredColumns, StackedBars, ClusteredBars, Pie, Grid, Bubble, Candlesticks, Spider, OHLC, Chart Theme, Tooltip, Base, functional, fold, scan, linear, colors, common, utils, Base, common, Base, reversed, fx, gradutils, sequence, Element, _PlotEvents, primitive, easing, Series, color, Palette, object, lambda, array, common, _base.

There are over 70 in all.  A few dozen seem to be related to charting, which is ironic given:

1. I am using google charts for all charting, and don't try to include any dojo chart tools at all
2. On startup my app prints out two warnings from inside dojo somewhere:
EXPERIMENTAL: dojox.charting.plot2d.Spider -- APIs subject to change without notice.
DEPRECATED: dojox.charting.Chart2D Use dojo.charting.Chart instead and require all other components explicitly -- will be removed in version: 2.0

Does anybody know how to get dojo under control?  I thought the whole idea of Dojo was that it would only bring in stuff that's needed?

Rex Bradford
Direct Relief International
0 Kudos
16 Replies
DanielNieto_Jr
New Contributor
My best guess are the libraries you are including have their own dependencies that they are also bringing in, I don't know if there is much you can do about that.
0 Kudos
RexBradford
New Contributor II
My best guess are the libraries you are including have their own dependencies that they are also bringing in, I don't know if there is much you can do about that.


Hmmm, thanks for the reply.  But I don't know of any libraries I'm pulling in that would do this - there are no other dojo.requires in the code.  My working assumption is that the dojo/esri library itself (http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5) is doing this on my behalf.

The only other libraries that are not in "my" code are:

ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js
ajax.aspnetcdn.com/ajax/jquery.ui/1.8.12/jquery-ui.min.js
http://www.google.com/jsapi
http://bit.ly/javascript-api.js?version=latest&amp........
jquery.tmpl.min.js (beta jquery template system, copied locally)

and none of them seem very likely to be requesting dojo modules.....

Rex Bradord
0 Kudos
JeffPace
MVP Alum
you are calling them, just indirectly.  For example you call

dojo.require(dijit.Dialog)

which has code

if(!dojo._hasResource["dijit.Dialog"]){
    dojo._hasResource["dijit.Dialog"]=true;
dojo.provide("dijit.Dialog");
dojo.require("dojo.dnd.move");
dojo.require("dojo.dnd.TimedMoveable");
dojo.require("dojo.fx");
dojo.require("dojo.window");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit._CssStateMixin");
dojo.require("dijit.form._FormMixin");
dojo.require("dijit._DialogMixin");
dojo.require("dijit.DialogUnderlay");
dojo.require("dijit.layout.ContentPane");
dojo.requireLocalization("dijit","common",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
dojo.require("dijit.TooltipDialog");
dojo.declare("dijit._DialogBase",[dijit._Templated,dijit.form._FormMixin,dijit._DialogMixin,dijit._CssStateMixin],{
   


so as you can see alot of the requires are being loaded by why you required.
0 Kudos
RexBradford
New Contributor II
you are calling them, just indirectly.  For example you call

dojo.require(dijit.Dialog)

which has code

if(!dojo._hasResource["dijit.Dialog"]){
    dojo._hasResource["dijit.Dialog"]=true;
dojo.provide("dijit.Dialog");
dojo.require("dojo.dnd.move");
dojo.require("dojo.dnd.TimedMoveable");
dojo.require("dojo.fx");
dojo.require("dojo.window");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit._CssStateMixin");
dojo.require("dijit.form._FormMixin");
dojo.require("dijit._DialogMixin");
dojo.require("dijit.DialogUnderlay");
dojo.require("dijit.layout.ContentPane");
dojo.requireLocalization("dijit","common",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
dojo.require("dijit.TooltipDialog");
dojo.declare("dijit._DialogBase",[dijit._Templated,dijit.form._FormMixin,dijit._DialogMixin,dijit._CssStateMixin],{
   


so as you can see alot of the requires are being loaded by why you required.


That makes sense, and what I assumed, but I was surprised for instance to see all of the charting stuff pulled in, when not called for explicitly.  Does Dialog pull these in too, or something else?
0 Kudos
JeffPace
MVP Alum
That makes sense, and what I assumed, but I was surprised for instance to see all of the charting stuff pulled in, when not called for explicitly.  Does Dialog pull these in too, or something else?


I have no idea why, but those are all pulled in when you
dojo.require("esri.layers.osm");

an must be an embedded component of OpenStreetMap
0 Kudos
RexBradford
New Contributor II
That makes sense, and what I assumed, but I was surprised for instance to see all of the charting stuff pulled in, when not called for explicitly.  Does Dialog pull these in too, or something else?


I did a little more testing.  It appears that

dojo.require("esri.layers.KMLLayer");

is responsible for pulling in all the chart stuff.  In fact, it pulls in about 45 of the roughly 70 modules I wasn't explicitly asking for.  I took it out as I'm not currently using KMLLayers.

Is this a bug?

Rex Bradford
Direct Relief International
0 Kudos
JeffPace
MVP Alum
I did a little more testing.  It appears that

dojo.require("esri.layers.KMLLayer");

is responsible for pulling in all the chart stuff.  I too it out as I'm not currently using KMLLayers.

Is this a bug?

Rex Bradford
Direct Relief International


no its not a bug.  If it is required for KML to work, it is required.  same with OSM.
0 Kudos
derekswingley1
Frequent Contributor
Jeff is right, it's not a bug. KMLLayer loads the charting modules. Why would you dojo.require it if you're not using it?

We had a brief discussion about the deprecation warnings on twitter this when we first added the KMLLayer:  https://twitter.com/#!/derekswingley/status/89451030831575041
0 Kudos
RexBradford
New Contributor II
no its not a bug.  If it is required for KML to work, it is required.  same with OSM.


Thanks.  Are the modules only pulled in by OSM when the layer is used though?  If I add dojo.require("esri.layers.osm"); to my code, I don't get all those charting modules.  With KML, just requiring seems to be all it takes to pull in the modules.

Rex Bradford
Direct Relief International
0 Kudos