Friday, March 10th, 2006

Post-Processing Javascript

Category: JavaScript

<>p>Do you post-process your Javascript? Are you an obfuscator, minifier, or gzipper? Douglas Crockford discusses these three forms of post-processing.

Minifying

A minifier removes the comments and unnecessary whitespace from a program. Depending on how the program is written, this can reduce the size by about half.

Obfuscating

An obfuscator also minifies, but it will also make modifications to the program, changing the names of variables, functions, and members, making the program much harder to understand, and further reducing its size in the bargain. Some obfuscators are quite aggressive in their transformations … Any transformation carries the risk of introducing a bug. Even if the obfuscator didn’t cause the bug, the fact that it might have is a distraction which will slow down the debugging process.

Gzipping

After minifying or obfuscating, you should GZIP. GZIP can further reduce the size of the program. GZIP is so effective that the difference in the efficiency between minification and obfuscation becomes insignificant. So I prefer minification with GZIP because I don’t have time for programming tools that can inject bugs into good programs.

Related Content:

Posted by Michael Mahemoff at 6:17 am
3 Comments

+++--
3.8 rating from 32 votes

3 Comments »

Comments feed TrackBack URI

Ajax – Three Reference Links

Starting with a link to an article about getting started with ajax that Danny posted on his blog I found…

Trackback by thirstycrow.net — March 10, 2006

For the commercial side of AJAX obfuscation is pretty important. We are playing with some different techniques to improve that side of things.

Comment by Dave Johnson — March 10, 2006

I don’t do minifying or obfuscation, myself – it just doesn’t seem worthwhile, and it is possible to get Apache to automatically gzip your .js files before sending them, so there’s really no need to even think about it.

However, I do usually take some time out to do some abstraction. This involves sitting down with a printout of the code, and seeing if I can spot any redundancies – two or three lines that I use quite a lot, or AJAX requests which could be easily cached. Then I take those bits and write a function for them.

Usually, this results in smaller code, which could potentially be a few microseconds longer, but /always/, it results in code that I can understand much better, and frequently re-use.

Comment by Kae Verens — March 12, 2006

Leave a comment

You must be logged in to post a comment.