JS compressor of world fame.

Open demo

Latest blog entries tagged "uglifyjs"

/** May the source-map be with you! **/


UglifyJS is a JavaScript compressor/minifier written in JavaScript. It also contains tools that allow one to automate working with JavaScript code:

All the above utilities and APIs are defined in ~6500 lines of code (except for the effective generation of the source-map, which is handled by the source-map module). Compared to alternatives, UglifyJS is pretty small.

These pages document the internals of UglifyJS. For a documentation of the command-line options please see the README.

Installing (for NodeJS)

You can install UglifyJS from NPM:

npm install uglify-js

but you can also use the Git repository if you feel adventurous:

git clone git://
cd UglifyJS2
npm link .

Building for the browser

Once you installed it for NodeJS, UglifyJS2 provides a quick way to build itself for the browser:

uglifyjs --self -c -m -o /tmp/uglifyjs.js

Now you have it in /tmp/uglifyjs.js and can include that single file in a browser. If you need source maps you'll also have to include the Mozilla source-map module. details to be clarified

Exported API

UglifyJS is written in “classic style”, so to say — it's not using the CommonJS module system (I find it more of an annoyance than of real help, especially for prototyping/development). To load it in NodeJS there's a single file that needs to be require-d: tools/node.js. If you installed it with npm install or npm link as mentioned above, then this file is loaded when you say var UglifyJS = require("uglify-js2"). This single file will load all the others in a separate execution context, so you should not worry about messing your global environment, and it returns a single object where all the global definitions in UglifyJS are exported.


Here are some stats showing where UglifyJS2 stands compared to other minifiers. Show charts.

Fork me on Github