UglifyJS — the name mangler

UglifyJS can reduce names of local variables and functions usually to
single-letters. That's a safe optimization provided the following stand:

You don't directly call the global eval function.

You don't use the with statement.

You don't access the Function.name property.

UglifyJS can detect the first two cases and it will disable the mangler
automatically in code areas that are poisoned by usage of eval
or with. UglifyJS cannot detect if you're using the
function's name property, however; in such code the mangler
can potentially break your code. For example
the JADE template engine is affected
by this issue (coupled with its
author “I am the
smartest and know what's best” attitude).

SYNOPSIS

That's all there is to it. Make sure to call figure_out_scope() first, then call mangle_names() on the
toplevel node. Optionally insert the compute_char_frequency()
there to get names that are optimized for GZip compression (names will be
generated using the most frequent characters first).

If you also compress your code, then you
want to mangle names after compression, since the compressor
might drop unused identifiers, unreachable code etc. The full sequence
would be this:

Latest blog entries tagged "uglifyjs"

UglifyJS 2 — online demo

Note that this is only tested with Chrome and Firefox. Should work
with Safari as well, but most probably not with Opera or IE.

Paste your code in the left box. Click “Uglify!” to get compressed
output on the right. The left-side will turn into
the Ymacs
editor. At this point if you click any token in the minified area,
the editor on the left will move to the original location of that
minified token.

Tick the “As I type” checkbox to turn on minification
on-the-fly.

When the compressor warns, you'll get a flashing button in the
toolbar. Click on it to display the warnings (temporarily covers
the minified area). Click a warning in the list to go to that
position in the source. If you have "on-the-fly" and fix warnings,
the list will update automatically.

You can enable/disable the compressor, mangler and beautifier. For
additional control check the buttons on the right
(“Compressor...” and “Codegen...”). Those
options are saved in localStorage, they will be remembered the next
time you visit this page.