JavaScript Minifier
Paste JavaScript to shrink it with Terser: dead code is removed, names are shortened and whitespace disappears. Syntax errors point to the exact line and column.
Runs in your browserNo sign-upNothing uploaded
How to use the JavaScript Minifier
- Paste your JavaScript or open a
.jsfile. - Choose options: Mangle names shortens local variables, Compress rewrites code into a smaller equivalent, ES module enables top-level
import/export. - Pick the ECMAScript target your users' browsers support. ES2020 is safe for all evergreen browsers.
- Check the size, savings and gzip estimate under the output.
- Copy the minified code or download it as
output.min.js.
What does a JavaScript minifier do?
Minification makes JavaScript smaller without changing what it does. This tool uses Terser, the minifier behind webpack, Vite and Rollup, and applies three kinds of changes:
- Whitespace and comment removal: indentation, newlines and comments are not needed by the JavaScript engine.
- Mangling: local variable and function parameter names such as
subtotalbecome single letters. Global names and object properties are left untouched so your public API keeps working. - Compression: constant expressions are folded, unreachable code is dropped,
ifstatements become ternaries and short functions are inlined.
Minify vs. gzip: do you need both?
Yes. Gzip and Brotli compress repeated byte patterns on the wire, while minification removes bytes the browser would otherwise have to download, parse and compile. A typical script shrinks 40–60% from minification and then another 60–70% from gzip. The gzip size shown here is a good estimate of what your server will actually send.
Keeping license comments
Many open-source licenses (MIT, BSD, Apache) require the copyright notice to stay with the code. By convention, comments that start with /*! or contain @license or @preserve are kept when Keep license comments is on.
When not to minify by hand
If your project already uses a bundler, let it minify production builds and generate source maps for debugging. An online minifier is ideal for one-off scripts, snippets for a CMS or tag manager, bookmarklets and checking how small a piece of code can get.
Frequently asked questions
Is my code uploaded to a server?
Can minification break my code?
Function.prototype.toString() or on local variable names through eval can be affected; turn off Mangle names in that case.