new version of JavaScript minifier in Perl

P

Peter Michaux

Hi,

I've uploaded a new version of the JavaScript::Minifier module that
was on CPAN. It was a translation of JSMin but I rewrote it so it now
handles missing semicolons, + ++ code, and leaves those freaky IE
conditional comments in the output. The goal was that if working code
is input then working code is output where working == working.
Breaking code that works is not such a good idea. :)

http://search.cpan.org/~pmichaux/JavaScript-Minifier/lib/JavaScript/Minifier.pm

Just thought someone here might find it useful in their build process.

Peter
 
L

-Lost

Peter said:
Hi,

I've uploaded a new version of the JavaScript::Minifier module that
was on CPAN. It was a translation of JSMin but I rewrote it so it now
handles missing semicolons, + ++ code, and leaves those freaky IE
conditional comments in the output. The goal was that if working code
is input then working code is output where working == working.
Breaking code that works is not such a good idea. :)

http://search.cpan.org/~pmichaux/JavaScript-Minifier/lib/JavaScript/Minifier.pm

Just thought someone here might find it useful in their build process.

Thanks!
 
P

Peter Michaux

Cool.
I was just wondering if javascript would run a lot faster with shorter
variable names - less time to lookup?

Shorter variable names will reduce download times. However if you gzip
files before serving then the reduction will be minimal because gzip
capitalizes on repeated patterns in a file. The main percentage gain
of minification is removing the comments. If the file will _not_ be
gzipped then there is also a big gain by removing whitespace. If the
file will be gzipped then the gzip handles the whitespace quite well
because it is a repeated pattern.

Shorter variable names won't make the JavaScript run faster because
the JavaScript is compiled when it arrives at the browser.
If this is the case then does anyone know of a minifier that would be
able to shrink the variable names to something smaller?

There are programs that reduce variable name size. This is usually
called obfuscation because it makes the code more difficult to read.
It is more difficult to write an obfuscator and so introducing bugs in
your working code is more likely. Also an obfuscator won't hide the
intention of your code from a reader who really wants to understand
it. Words like function, for, this, document, window, etc are not
normally obfuscated. A major effort would need to be made to obfuscate
these words and the code to unubfuscate it would also be in the
JavaScript (unless flash was used to unobfuscate, I suppose, but even
then the reader could use the flash to unobfusicate the code (it is
futile)).

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top