Which JavaScript minifier (cruncher) does the same things that the one Google uses for its JavaScript APIs?
Asked Answered
A

6

29

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 (e.g., function1 → a, function2 → b, and 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 a JavaScript minifier in the whole Internet with those features. Is there one?

Aseptic answered 28/1, 2009 at 23:12 Comment(3)
The term "minifier" is used for those tools that remove unnecessary whitespace to minimize download size. The term "obfuscator" is used tor those tools that can rename identifiers, even if that renaming results in shorter names and thus minimizes download size. Most obfuscators also minify be stripping whitespace.Gaggle
Just to make sure, I checked the Google web site: code.google.com/p/minify It is clearly labelled "minify". There is no evidence at that site that any variables get renamed.Gaggle
@Ira, look internally. External facing variables are not renamed, but internal only variables are, as @Jader noticed.Hames
C
62

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.

Carrnan answered 24/11, 2009 at 8:31 Comment(1)
Google even has an API that lets you do this, meaning that you could set up a script that automatically uses the google minifyer/obfuscator, see developers.google.com/closure/compiler/docs/…Marniemaro
H
10

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.

Hames answered 28/1, 2009 at 23:31 Comment(4)
I don't think this answers the question at all.Upcast
It doesn't answer the question. It lists "minifiers" rather than "obfuscators".Gaggle
That's not quite true; the YUI Compressor apparantly obfuscates just local variable names.Gaggle
"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.Hames
C
3

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 (old)

YUICompressor (new)

Chantell answered 28/1, 2009 at 23:31 Comment(1)
Now deprecated?Madonnamadora
C
3

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

  • integrate the minification/file combining into Visual Studio post-build events
  • integrate into a TFS Build (including CI)
  • if you wish to just use the DLL files in your own code (e.g., on the fly minification).
Cotidal answered 7/7, 2009 at 0:17 Comment(0)
S
2

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

Sophistication answered 15/4, 2009 at 0:36 Comment(0)
G
2

You are describing 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.

Gaggle answered 7/9, 2009 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.