0

Now, I've heard of javascript compressors, used a bunch and favour a few. However, they all do the same thing. Remove unnecessary space. That's great, they do exactly what it says on the tin. Compresses Javascript. However, looking through some of the major players that provide legendary libraries (such as jQuery), they offer "minified" sources that are entirely unreadable. Notably, the variable names change from someThingLikeThis to c. This is compression that I cannot seem to find anywhere.

My question is, where can I find a Javascript compressor which compresses variables in addition to removing unnecessary space. Or is it done manually?

For example:

// My Javascript:;

var cats = 'Nyan',
    dogs = 'Hound';

alert(cats + dogs);

// jQuery styled compression:

var a='Nyan',b='Hound';alert(a+b);
nderjung
  • 1,607
  • 4
  • 17
  • 38

3 Answers3

2

As far as i know http://developer.yahoo.com/yui/compressor/ Does what you need :)

Lemex
  • 3,772
  • 14
  • 53
  • 87
1

That should be done by a standard minifier. If it is not, then most likely the variable names just cannot be renamed safely (global variables/functions).

Also what you might be looking for is obfuscator. Check this question: How can I obfuscate (protect) JavaScript?

Community
  • 1
  • 1
niaher
  • 9,460
  • 7
  • 67
  • 86
0

Google Closure Compiler is the most advanced tool to transpile/minify JavaScript code.

It basically features two compilation levels—simple and advanced. You can use the simple compilation level on pretty much any JS code.

The true magic is in the advanced level which removes unused code, inlines functions, flattens properties (abc.def.ghi -> a) and renames all custom variables. But you have to write the code in a way the compiler can understand.

If you're serious about JS, read the "Closure: The Definitive Guide" by Michael Bolin who is one of the lead developers of the Closure Tools.

J. K.
  • 8,268
  • 1
  • 36
  • 35