Tuesday, November 16, 2010

Why Intraweb Javascript is not minified?

Well, mine are! ;-)

After a lot of IW JavaScript debugging I asked myself: Why IW JavaScript code is not minified? You know, those .js files included in the header of the page generated by an Intraweb web application....?

If you want to know more about JS minification, you can read here. Simple performance comparisons can be seen here. You may note that the performance may increase up to 50% depending on the original, not minified, JavaScript file.

Well, If Atozed doesn't minify their JavaScript, I can minify them myself. All JavaScript code distributed with Intraweb is inside the resource file IWData.res (look inside the DCU folder).
To minify the scripts I've used two different tools: A resource tool to export IW JavaScript inside the resource file, and a JavaScript minifier. The resource tool was Resource Hacker (old and good resource utility written in Delphi 3, still very useful). Just open the IWData.res using Resource Hacker and you will see something like that:

You can export all the RCData resouces with a single operation choosing the menu option shown above. Choosing this option, Resource Hacker will save all RCData resources and a .RC file. With those files you will be able to recompile IWData.res from modified (minified JavaScript) files. In my IW version (10.0. 0.17) the saved files from 51 to 68 are the JavaScript internal files.

After that, I used the JavaScript Obfuscator to minimize it (there is a fully functional evaluation version available). You can use any JS compressor/minifier, like the excellent YUI online compressor. After compression, all the JavaScript files were reduced to 107 KB (275 KB before compression), 39% of their original size!
Then, you can recompile IWData.res, using the .rc file generated by Resource Hacker, using Delphi's own resource compiler (brcc32.exe, in BDS 2006). Copy the recompiled IWData.res to the IW dcu folder replacing the original file (backup the original FIRST!), and you are ready to go!
You will have a faster IW application and as an extra bonus your ISAPI DLL will be 170 KB smaller! :-)

Note: I've tryied the JavaScript Obfuscator tool to minify and obfuscate IW JS libraries, but later I've found out that the resulting JavaScript was tooooo dammmn slow. So I'm only minifying it using YUI online compressor

No comments: