jsminify -- remove comments and most other whitespace from a javascript file

by Eugene Reimer 2007-August

I was hoping to use Douglas Crockford's jsmin to minify my javascript programs.  However it only promises to work correctly on files that pass his jslint.  And his jslint outlaws several programming practices I'm unwilling to give up (such as writing a trivial for-loop on one line without braces), so I wrote this bash script as a simpler alternative to his jsmin.  Mine can be safely used on any javascript.  No jslint needed!!  The space-saving is much the same as with his: my 110KB testcase shrinks to 36.6KB with his, or with mine. 

Handles input in UTF-8 or ISO-8859-1 or any charset that has ASCII as a subset.  Limitation: it only handles //...  comments, not the /*...*/ kind. 

When my first attempt was foiled by sed's behaviour on a command such as  s|\(...\)*...|\1|  the sed solution got so ugly that any reasonable person would've switched to something else, but I didn't:-)

Here is the bash script jsminify

Send bug-reports, comments, or suggestions to ereimer@shaw.ca.