compressing javascript code in perl
While sneaking around the web tonight looking at sites which have interesting dhtml controls or cool stylesheets, I came across this article:
http://www.bazon.net/mishoo/articles.epl?art_id=209
I couldn't help but start pulling apart some of those regex's. The one which strips whitespace at the beginning and end of lines is quite familiar:
\n)\s+|\s+(?:$|\n))
This regex is basically saying:
either anchor at ^ or \n and slurp all
whitespace
or
slurp all whitespace up until the $ or \n
anchors
so, while the alternation is costly, overall the regex is very readable and maintainable. The C-style comment regex on the other hand seems way too complicated compared to my C-style regex which can be found at RegexLib.com here:
http://regexlib.com/REDetails.aspx?regexp_id=445
Overall though, it's not the regex whackiness that I wanted to highlight; it's the script. This seems like a nice, lean way to reduce the byte size of js code files.