Free tool
JavaScript minifier and beautifier
Free · no sign-up · runs in your browser, nothing is uploaded
Working…
What each Terser option does
This page runs Terser 5, the minifier inside many JavaScript build tools. The toggles map directly to Terser options, so a setting you like here can go straight into your build config:
| Option | Terser setting | What it does |
|---|---|---|
| Compress | compress | Rewrites code to shorter forms: folds constants, removes dead branches, joins statements |
| Mangle names | mangle | Renames local variables and parameters to one or two letters |
| Top-level scope | toplevel | Also renames and drops unused top-level variables and functions. Only safe if no other script uses them |
| ES module | module | Treats the input as an ES module: strict mode, and top-level names can be mangled |
| Drop console.* | compress.drop_console | Removes console.log, console.warn and the other console calls |
| Keep function names | keep_fnames | Keeps function names for code that reads fn.name, and readable stack traces |
| Keep /*! license */ comments | format.comments: "some" | Keeps comments with @license, @copyright or @preserve, or that start with ! |
| Passes | compress.passes | Runs compression up to 1, 2 or 3 times; later passes sometimes find a bit more |
| Source map | sourceMap | Builds a .map file and adds a //# sourceMappingURL comment pointing to it |
Real output from the minifier on this page, with the default options:
| Input | Terser output |
|---|---|
| if (debug) { log("x") } | debug&&log("x"); |
| let x = 1 + 2 * 3 | let x=7; |
| function f() { return true === x ? "a" : "b" } | function f(){return!0===x?"a":"b"} |
| const veryLongName = 1; console.log(veryLongName + 1) | const veryLongName=1;console.log(2); |
In the last example veryLongName is not renamed: it is a top-level name, so another script might use it. Turn on Top-level scope and the whole line becomes console.log(2);.
Minify JavaScript from the command line or Node
The Terser command line, with compression, mangling and a source map:
npx terser app.js --compress --mangle --source-map --output app.min.js # writes app.min.js and app.min.js.map
The Node API is async and returns the code and the map:
import { minify } from 'terser';
const result = await minify(source, {
compress: { drop_console: true },
mangle: true,
sourceMap: { url: 'app.min.js.map' },
});
// result.code, result.mapesbuild minifies too, and is often used for speed when you bundle with it anyway:
npx esbuild app.js --minify --sourcemap --outfile=app.min.js
If you use a bundler, production builds usually minify already. Use this page for a single script, a snippet for a CMS or an embed, or to see what an option changes.
Source maps
A source map is a JSON file that links each position in the minified file back to the original. With it, browser dev tools show your readable code in errors and the debugger. Turn on Source map, then download both files: the minified script ends with //# sourceMappingURL=script.min.js.map, so keep the two files side by side on your server.
A public source map also shows your original code to anyone who opens dev tools. If that matters, upload the map to your error tracker instead of serving it.
When minified code behaves differently
- Code that reads names. Mangling renames functions and classes, so
fn.nameandconstructor.namechange. Turn on Keep function names if your code or a library depends on them. - Globals shared between scripts. With Top-level scope on, top-level names are renamed or dropped. Leave it off for classic scripts that define globals for other files.
- eval and with. Terser does not mangle names in scopes that use
evalorwith, so such code stays bigger. - Syntax errors. Terser needs valid JavaScript. JSX and TypeScript must be compiled first. The error box shows the line, column and the code around it.
Minifying a whole page? The HTML formatter minifies inline scripts and styles in Minify mode, and the CSS minifier handles stylesheets. For more developer tooling, browse code tools on DevHunt.
More free developer tools
FAQ
What is a JavaScript minifier?+
A tool that rewrites JavaScript into a smaller program that does the same thing. It removes comments and whitespace, shortens local variable names (mangling) and simplifies code (compression), for example if (debug) { log("x") } becomes debug&&log("x"). Smaller files download and parse faster.
What is the difference between minify, uglify and obfuscate?+
Minify and uglify mean the same thing; people say uglify after the UglifyJS tool. Both aim for small code. Obfuscation aims for code that is hard to understand, often making it bigger and slower. Minified code is hard to read but easy to reformat, so don’t rely on it to hide secrets.
Can minified JavaScript be reversed?+
Partly. Beautify mode (or "Beautify the result") restores line breaks and indentation with Prettier. The original local variable names and comments are gone for good. If you have the source map, browser dev tools can show the original source.
Will minification break my code?+
Not with the defaults, as long as the input is valid JavaScript. The usual surprises are code that reads Function.prototype.name or class names at runtime (turn on "Keep function names"), and global names another script uses (keep "Top-level scope" off, the default). Test the minified build before you ship it.
Is Terser better than UglifyJS?+
Terser started as a fork of uglify-es, at a time when UglifyJS could not handle ES2015+ syntax, and kept a compatible API and command line. Both are maintained today. Terser is the engine behind terser-webpack-plugin and @rollup/plugin-terser, so its output matches what many builds already ship.
Can I minify TypeScript?+
Compile it to JavaScript first (tsc, esbuild or your bundler), then minify the output. Beautify mode here understands TypeScript and JSX if you only need to format it.
Is my code uploaded?+
No. Terser and Prettier run in your browser and nothing is sent to a server. Short inputs are kept in the page address so you can share a result.
Sources: Terser README · esbuild API: minify · MDN: source maps · Prettier options. Checked 2026-10-29.