Last week I wrote about the JavaScript Crunchinator, a tool for converting your well-indented, good-looking scripts into a less readable but more compact form. Thanks to some reader comments on that post, I have found out about a few similar tools:
-
Angus points out his own tool, CodeTrimmer, which also crunches scripts and provides some useful options, like whether to remove comments.
-
John and Ken mentioned Packer by Dean Edwards, a similar tool.
-
Jeremy recommends Bookmarklet Builder, a specialized cruncher for bookmarklets that lets you work with a readable version of your code and produce a one-line compressed script as output.
-
Jeremy also mentioned PrettyPrinter.de, the opposite of these tools. If you're faced with a crunchinated script, this tool adds appropriate whitespace and newlines to make it more readable. It works with JavaScript, PHP, Java, C, C++, Perl, and CSS.
Last but not least, Marek has a good point in his comment: if you enable gzip compression on your web server, most browsers will be sent a compressed version anyway, which makes the whole point of squashing scripts to save bandwidth moot. You may want to consider using this at the server level rather than messing with your scripts if that's an option.







