Squish it good - Code compression for the masses

Labor Day came and I completely forgot that it would mean no Monday morning for writing a post. Hope you all had great beer and burgers, or whatever you were doing.

In the meantime, I’d like to mention something cool. Julien LeComte has released his YUI Compressor that includes a CSS minification script that I built here for internal use.

Compression is a little more than just minifying. Julien’s compressor also shortens all local variable names, resulting in significant improvements over minification alone, but without the bug-risks of obfuscation.

It’s interesting to me that his tests show that compression is actually more effective than obfuscation when the code is gzipped. I’m not enough of a gzip scholar to know why that is, but in my mind at least, it shuts packer’s Base 62 encoding out of the running. Additionally, in my (non-scientific, not statistically significant, but probably still accurate) tests, packer adds a significant amount of run-time due to the convolutions of eval and a needless large Regex. You need to have pretty big download gains in order to make it worth putting the browser through that extra work.

Say it once, say it forever, say it to yourself at night, teach it to your children: Javascript obfuscation is pointless and dangerous. You don’t get enough download savings to justify the risk of bugs, you can’t really hide your code, and when gzipped, compression is better anyhow.

The CSS Compressor that I wrote doesn’t do what CSS Tidy does. There are a few steps that could be taken from CSS Tidy, like shortening margin:1px 1px 1px 1px to just margin:1px. It doesn’t merge properties or background properties. Like JSMin and the YUI Compressor’s javascript minifier, it tries to err on the side of not affecting functionality in any relevant way, while attempting at the maximum compression possible within that boundary.