Mon 22 Jan 2007
Dojo project contains a lot of facilities, however not all of them are useful for a given user. We provide a build system which removes inline comments and rename local variables with shorter names (3 characters), among other optimization.
Even after this building procedure, the resulting dojo.js can still be a bit big: for a normal widget build, the size is 170k (dojo trunk).
Recently when searching for IE hover css selector support, I revisited Dean Edwards’s website. Packer project attracted my interest and I decided to give it a go with the built dojo to see whether further compression can be achieved.
The result is quite promising: after packing, the resulting widget build of dojo is almost 50% smaller. The compression ratio is 99893/170258= 58.7%.
Looking at the packed version, all the comments and source formating new lines are removed. Some other compression is happening as well, but as I did not investigate its source code, I do not know exactly what it does, but it seems to me that by storing the publich API name and all the strings in the source at the last, it achieves some extra compression ratio. (Don’t worry, the compression does not change the meaning of the javascript code it packs, and I tested that in one of the applications I am working on.)
As the source code is in javascript, it should be simple enough to incorporate this to the dojo builder. Probably this should be the last "filter", before writing the output file: for all the source js files, they should be passed through this packer, and then copied to the release dir, so does the resulting dojo.js.