Dojo issues

We use dojo 1.7.2 in our application. Although AMD supported in this version, we do not use this approach at all. We are still with the deprecated dojo.require("package") approach.

We need to create a release build for our application. Below is the profile we use for this. For this we use the ANT task. Our profile is very simple and does not have a lot of dojo in it.

 dependencies = { layers: [ { name:"cutom_dojo.js", resourceName:"custom-dojo", dependencies:[ "dojo.NodeList-traverse", "dojo.io.iframe", "dojo.date", ] } ], prefixes: [ [ "dijit", "../dijit" ], [ "dojox", "../dojox" ] ] } 

Now we are creating the release build using the following ANT task.

 <target name="create-dojo-release"> <echo message="Starting Dojo Release Build " /> <java fork="true" dir="${shrinksafe.util.path}/buildscripts" classname="org.mozilla.javascript.tools.shell.Main"> <classpath> <pathelement location="${shrinksafe.util.path}/shrinksafe/js.jar" /> <pathelement location="${shrinksafe.util.path}/closureCompiler/compiler.jar"/> <pathelement location="${shrinksafe.util.path}/shrinksafe/shrinksafe.jar" /> <pathelement path="${java.class.path}" /> </classpath> <arg value="../../dojo/dojo.js"/> <arg value="baseUrl=../../dojo"/> <arg value="releaseDir=${dojo.release.dir}"/> <arg value="load=build"/> <arg value="profile=${dojo.profile.file}" /> <arg value="action=clean,release" /> <arg value="version=1.7.2" /> <arg value="releaseName=cutom_dojo" /> <arg value="cssOptimize=comments" /> <arg value="copyTests=false" /> </java> <echo message="Dojo Release build successfull." /> </target> 

We get the custom_dojo.js file in the dojo folder. We have included this JS file in our application. When we open this JS file and look for packages that are mentioned in the layer, they are all available there. But when we turn to the application page, we still see that individual HTTP requests are sent for individual modules, although the custom_dojo.js file is located at the top of the page. Could you suggest us if we do it right?

+4
source share
1 answer

you seem to be writing your build profile to the old legacy format. The new (post-V1.6) way would be this:

 var profile = (function(){ return { basepath: ".", packages: [ {name: "dojo", location: "./dojo-release-1.7.4-src/dojo"} ], layers: { "dojo/custom_dojo": {include: [ "dojo/NodeList-traverse", "dojo/io/iframe", "dojo/date" ]} } }; })(); 

Of course, replace your own paths, etc. Also note that I am specifying module identifiers with a new forward slash instead of the old dotted notation.

Then I built it as follows:

 dojo-release-1.7.4-src/util/buildscripts/build.sh --release --profile test.profile.js 

I tried this with the build profile above, using Dojo 1.7.4 (latest version 1.7) and using the following test page, it works as expected without reloading the modules.

 <!DOCTYPE html> <html> <head> <title>test</title> <script type="text/javascript" data-dojo-config="async:0" src="./dojotk/dojo/dojo.js">/*empty*/</script> <script type="text/javascript"> // load the custom layer dojo.ready(function() { dojo.require('dojo.custom_dojo') });; // to be called on button click function myFun() { var ifr = dojo.require('dojo.io.iframe'); // check module has been loaded if (ifr) { alert('success: '+ifr); }; return false; } </script> </head> <body> <input type="button" value="click" onclick="return myFun();" /> </body> </html> 

Links It is true that I had to learn this difficult path, since the documentation is not too easy to read, and the examples from Dojo sources use a combination of the old and the new build profile format, which also does not help. However, these links are very useful.

Enjoy Martin

0
source

All Articles