Nobody Wants to See Your Whitespace: Minify CSS and Javascript using Yahoo!’s UI Compressor
Tuesday, April 21st 2009Beating rule #10 is easy. We want to serve CSS and Javascript that has been minified (and obfuscated, if you please) to our readers, because that's less overhead for them to download. We also want to do it without screwing up our code, so I recommend using Yahoo!'s UI Compressor.
Now, would-be ultra-"l33t" programmers might enjoy using a command line, but I sure don't. It's a waste of the time Darwinian evolution spent on developing my eyeballs. Instead, swing on by to this cool guy's website, http://refresh-sf.com/yui/, where you can just copy paste your CSS or JS into a text field and get it minified/obfuscated without fiddling with Stone Age command prompts.
What happens when we have to make changes to our files after they've been minified/obfuscated? Since I don't use a fancy development environment to handle my files, I just minify/obfuscate the files that are up on the server and leave my local files alone. If I need to make a quick CSS change, I make them locally and just find/replace the same lines on the server. Janky? Yes. Not ideal? Sure. But it works.
* Keep one thing in mind when you minify/obfuscate: comments get stripped out entirely, and usually the software license or developer credit for freeware is contained in those comments. After some meditation on this matter, I decided that it's silly to keep the comments in after minification; that would be doing it half-assed and ultimately it defeats the purpose. As a compromise, we should have a page in our website that credits the creator of source code we borrow from the open source community. This provides even more visibility for our open source colleagues while allowing us to fully minify our files.

You can keep comments by starting them with a /*!
/*! this is a comment */
will turn into
/* this is a comment */
http://www.julienlecomte.net/yuicompressor/README
Oh wow, thanks for noting this. Very helpful in keeping the license information. (We still face the problem of whether we ought to keep the byte size that comes with the information, rather than compressing it, however. Some licenses permit us to credit them elsewhere, but of course with most, removing the data via compression violates the agreement. I suppose this is another quandary where copyright and its derivatives brush up against utility in technology.)