How to use the JavaScript minifier
- Paste your code or drop one or more
.js,.mjsor.cjsfiles onto the page. - Choose a preset. Balanced suits most code; Safe keeps function and class names; Max squeezes harder.
- Set the options: keep license comments (on by default), mark the code as an ES module, keep names, or create a source map.
- Press Minify. The first run loads the Terser engine in the background; later runs are instant.
- Copy or download the result, compare it with the original in the diff view, or measure gzip and brotli sizes.
How it works
Terser parses your code into a syntax tree, then rewrites it: removing whitespace and comments, shortening local variable names (mangling), folding constants, dropping unreachable code and simplifying expressions. It prints the tree back out as compact JavaScript.
| Preset | What it does |
|---|---|
| Safe | One compression pass; keeps function and class names; no unsafe transforms |
| Balanced | Two compression passes; mangles local names |
| Max | Three passes; also mangles top-level names when the code is an ES module |
The work runs in a Web Worker, so even large files don’t freeze the page. A 30-second time limit and a Cancel button stop a job that runs too long.
Worked examples
- A small utility module of 1.2 KB with comments and descriptive names typically shrinks to well under half its size, and its
/*! … MIT */notice stays at the top. - Minifying twice gives the same or a smaller result, never a larger one, so it’s safe to re-run on already minified code.
- A syntax error such as a missing value after
=is reported with its line and column, so you can find it quickly.
Tips and common mistakes
- Test the output. Minifiers are reliable, but code that reads its own function names (for example some dependency-injection libraries) needs Keep names.
- Don’t strip licenses you’re required to keep. Leave Keep license comments on for third-party code.
- Serve with compression. Minification and gzip or brotli work together; compression usually saves more than minification alone.
- Keep the source. Minified code isn’t meant to be edited. Keep the original under version control and minify again after changes.
Why use this minifier
It runs entirely in your browser with a well-known engine, explains its trade-offs, shows real gzip and brotli numbers, handles batches with a ZIP download and supports source maps, all with an accessible, keyboard-friendly interface and no ads inside the editor.