views:

2843

answers:

6

I am a Google Maps API (javascript) developer. I have noticed that Google uses a Javascript minifier that has the following features:

  1. Shortens variables, properties, arguments, classes, function and method names, obfuscating the code. (eg. function1 -> a, function2 -> b, function3 -> c)
  2. Some variables, classes, properties and methods can be marked to not be crunched, so its name remains the same as documented in the API manual.
  3. It is rerun in each subversion of the API, like a build task, I noticed that because of the crunched names changes from one version to another.

I have not found in the whole internet a Javascript minifier with those features. Anyone knows one?

+2  A: 

I believe that YUICompressor does #1, except for the function names, and #2 using a special syntax that is removed during compression.

#3 is just a build task, not a function of the compressor.

YUICompressor

slolife
+4  A: 

Here are the minifiers I know of: Dean Edwards' packer; YUI Compressor; JSMIN; and Dojo compressor

In addition to these, the GWT compiler does quite a bit to make efficient JavaScript files out of Java files. It wouldn't surprise me if that is what they use.

geowa4
I don't think this answers the question at all.
Jorge Vargas
It doesn't answer the question. It lists "minifiers" rather than "obfuscators".
Ira Baxter
That's not quite true; the YUI Compressor apparantly obfuscates just local variable names.
Ira Baxter
"The YUI Compressor is JavaScript minifier designed to be 100% safe and yield a higher compression ratio than most other tools." Sounds like a minifier to me--which is what @Jader wanted. Internally, YUI obfuscates, but everything that is available externally is left untouched. How is that not what @Jader wanted? I think the best proof that this does actually answer his question is the little green checkmark that this answer has.
geowa4
+1  A: 

A simple online javascript minifier based on dojo's shrink safe can be found at http://netspurt.com

+2  A: 

There's also a .NET port of YUI Compressor which allows you to:-

  • intergrate the minification/file combining into Visual Studio post-build events
  • intergrate into a TFS Build (including CI)
  • if you wish to just use the dll's in your own code (eg. on the fly minification).
Pure.Krome
+1  A: 

What you are describing is an "obfuscator" not a minifier, and they are easily found by searching for "Javascript obfuscator".

Our SD Thicket ECMAScript Obfuscator both obfuscates and minifies at the same time.

Ira Baxter
+15  A: 

Google has now opened up the minifier they use along with some other internal javascript goodies.

It's all under the name "Closure Tools" and was announced earlier this month.

Aaron Wagner