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

Wednesday, November 10, 2010

Doing nice things with Intraweb + jQuery!

Well, the first example I saw using Intraweb and jQuery playing together was a nice post from Hadi Hariri (Originaly here, but the page is gone. You still can read it in google cache, here).
Then, in IW 10 I saw a new component "TIWjQueryWidget". Fotunately, it came with sources, and I could see that it is simple, very simple indeed.
I already knew a little about jQuery and I saw that it would be relatively simple to use in with Intraweb (would it?).
What do you think that IW misses most? For me: Maybe, a nice Ajax enabled data grid, modal dialogs, a nice looking page control/tab sheet container, some mask inputs and some other minor things. Well, I've started from the most challenging one (at least, before any knowledge about it!): the data grid. I've choosen jQGrid. A nice, beautiful, simple and well written ajax grid. I wish (Win32) Delphi's DBGrid was as good as (Web) jQGrid!
Many, many hours of work during my spare time, almost a second divorce ;-) and voilá! I've made it work! Not much Delphi code, but due to the lack of Intraweb source code, books, articles and examples I had to search every little piece of information in newsgroups, blogs and IW - very restrict - sources. Now I see why IW is not a killing framework to create web applications: Chad kept the source code closed for toooooo damn long (still today)! It is just too hard to understand the "meat" of IW without the source code! The reason that thousands of developers started to write good components for Delphi - making Delphi a terrific tool back in 1995 - was just because the best teacher was there in your hard disk: RTL/VCL sources!

Well, back to IW + jQuery: The jQGrid is working. A limited version of it, but it works pretty damn good for now. I'm proud and happy to use it today in a production environment, in a respected brazilian bank (internal) web application. This bank is among the 60's biggests in the world. For you foreigner that may ask "what? a brazilian bank?". You'd better think twice! Brazil has one of the most advanced banks in the world, when we talk about software and technology (the same can be said about elections! After all, we knew our next president 3 HOURS after the voting finishes ;-) ).

Soon I will put some IW + jQuery demos live, at work!

Below a little screen shot of my IWjQGrid using the old "country" table, from Delphi demos!



I would like to know what you think about it.