Sunday, 6 September 2009

Build it.. No really... Build it

Dojo is a framework. I'll say that again... A Framework.

Why I stress this is that it's package system and lazy loading are something that makes dojo development amazingly clean and modular, but as a side effect it can also be less efficient in production code unless you pay attention to that build system.

Each time you hit a dojo.require call, dojo lazy loads code via xmlhttp request objects. A few calls is simple enough, but from my experience, creating these, pulling in code and tearing them down can be quite expensive time wise if you get heaps of them in a row. This is something you'll notice if you visit the archive.dojotoolkit.org site tests as the code used is the completely raw source meaning as slow as you can get.

So what can the build system do to help?

The build system is quite simply, amazing. Shrinksafe not only merges js files using all the dojo.require dependancies, it can strip out comments, strip out console logging statements, rename variables to shorter names and condense code to a single line... and that's not all. It can apply levels of compression on the CSS files too. Hence not only are there fewer requests to bring in code but the code itself is smaller. Pulling in the bulk of your code via what is termed a layer file speeds up page loads but the require system is still in effect, allowing you to pull in extra code as you need it.

You'll need a source build of dojo to do this, one that includes the Utils directory and the buildscripts subdirectory. I usually jump into the nightly source package as a quick start (http://archive.dojotoolkit.org/) or you can grab the subversion source. Once you have it, go into util / buildscripts. There you'll find build.sh and build.bat depending on your operating system.

Running the build file with no arguments is one of the best ways to see what you can do. It will list out a heap of comments. My advice is to read through these as a means of figuring out what else to read up on.

I could go on but I don't have to as dojo campus have all the steps you need for building dojo: http://docs.dojocampus.org/quickstart/custom-builds

Starting Fresh

I was reading the post "What is the future of dojo" and to be honest I skipped through it a bit towards the end.

I struggle with some of what was said. I've been using dojo since 0.3 and am really not surprised that there's stale information out there. It's been a front runner pushing ideas and culling off others that were less useful. To me the stale information shows just how much has been achieved over the last few years. Having said that I myself was contributing to this with information no longer relevant so in the spirit of moving forward I've nuked my past entries and shall work towards producing more relevant information.