Improve dojo performance in Zend Framework
Posted by Faheem Abbas on January 7, 2009
After using dojo calendar in my application, I feel that it take lot of time loading dojo js files. This not only bothered me but also the client I am working with. However yesterday when listen a webinar of Methew -Zend framework architect and responsible for framework and dojo integration, I come to conclusion that the requests can be limited to one or two by using custom builds.
As I was new and was unable to understand it from the webinar, I visited dojo toolkit website and read article about custom builds there. Although that article can help you however they don’t have given how to use it with the Zend Framework.
So in this post I am going to discuss how you can improve performance of dojo by limiting the number of request.
So let’s get started.
First go to “dojo/util/buildscripts/profiles” and create foo.profile.js and write the following code in it.
dependencies={
layers: [
{
name: "custom.js",
dependencies: [
'dijit.form.Form',
'dijit.form.Button',
'dijit.form.DateTextBox',
'dijit.form.Checkbox'
]
},
],
prefixes:[
['dijit','../dijit'],
['dojox','../dojox'],
]
}
Save this file and open command prompt in window/linux
Now in script go to the util/buildscripts using command as
C:\> cd xampp/htdocs/Zend/js/dojo/util/buildscripts/
Keep in mind that you may have different directory structure. So you will need to change this path. Now write
C:\ xampp/htdocs/Zend/js/dojo/util/buildscripts> build.bat profile=foo action=release
After executing
build.bat profile=foo action=release
You will find a new directory “release” created in you dojo directory. This is the compact version of the dojot toolkit.
Note: use build.sh instead of build.bat in the command if you are using linux.
Now this is the directory for your production. Copy this directory to your application and set your apths in the layout file as
$this->dojo()->setDjConfigOption(‘usePlainJson’,true)
->addStylesheetModule(‘dijit.themes.tundra’)
->setLocalPath(“/js/dojo/release/dojo/dojo/dojo.js”)
->addLayer(“/js/dojo/release/dojo/dojo/custom.js”);
echo $this->dojo();
Not that we have only setLocalPath and addLayer(). addLayer() contain path to the cutom file you create in the foo.profil.js. this file will be generate for you and will be placed in the realease/dojo/dojo/ directory.