Shrink JavaScript files before deploying a website to speed up load times
Obfuscate source code by shortening variable and function names using the mangler
Generate source maps so compressed code can be debugged in the browser's devtools
Integrate minification into a build pipeline via the JavaScript API
UglifyJS is a toolkit for processing JavaScript files. Its main use is minification: taking readable JavaScript source code and compressing it into a much smaller file that works the same way but takes less time to download. Smaller files matter because websites typically load JavaScript from a server, and large files slow that down. The toolkit does several things. The parser reads JavaScript and builds an internal representation of the code. The compressor rewrites that representation to be more efficient, removing dead code, collapsing expressions, and applying various logic transformations. The mangler shortens variable and function names from descriptive words to single characters, which saves space without changing behavior. A beautifier does the opposite: it takes compressed or unformatted code and makes it readable again with proper indentation. Both a command-line tool and a JavaScript API are provided. The command line takes one or more input files, runs the selected steps, and writes output to a file or to standard output. You can control exactly which features to apply with flags: compression, mangling, property name mangling, and beautification all have their own switches and sub-options. Source maps are supported, which allow browsers to map the compressed code back to the original source for debugging. The tool supports most JavaScript syntax, including modern ECMAScript features. For very new or exotic syntax it recommends running a tool like Babel first to convert the code to something UglifyJS understands. The v3 API is not backwards compatible with the older v2 series. Installation is a single npm command, either globally to use it from the terminal or locally to use it inside a project. The full README is longer than what was shown.
← mishoo on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.