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. (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?

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
  • 1
    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. – Ira Baxter Sep 07 '09 at 08:14
  • 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. – Ira Baxter Sep 07 '09 at 08:58
  • 1
    @Ira, look internally. External facing variables are not renamed, but internal only variables are, as @Jader noticed. – geowa4 Sep 07 '09 at 15:29

6 Answers6

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.

Aaron Wagner
  • 5,739
  • 1
  • 31
  • 38
  • 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 https://developers.google.com/closure/compiler/docs/gettingstarted_api?csw=1 – Thijs Riezebeek Mar 20 '15 at 00:19
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.

geowa4
  • 40,390
  • 17
  • 88
  • 107
  • 10
    I don't think this answers the question at all. – Jorge Vargas Sep 07 '09 at 06:27
  • 2
    It doesn't answer the question. It lists "minifiers" rather than "obfuscators". – Ira Baxter Sep 07 '09 at 08:19
  • That's not quite true; the YUI Compressor apparantly obfuscates just local variable names. – Ira Baxter Sep 07 '09 at 08:41
  • 2
    "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 Sep 07 '09 at 15:36
3

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
  • 84,693
  • 113
  • 396
  • 647
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

slolife
  • 19,520
  • 20
  • 78
  • 121
2

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
  • 93,541
  • 22
  • 172
  • 341
2

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