What minification does
Minifying rewrites JavaScript so it behaves identically but takes fewer bytes. This tool uses Terser, the same minifier behind most modern build tools. It removes comments and whitespace, mangles local variable and function names to one or two letters, and compresses the code itself: it folds constants, removes unreachable branches, inlines single-use variables and joins statements.
Paste code or drop a .js file, choose your options and press Minify (or Ctrl+Enter). The result shows the size before and after. Terser runs in a Web Worker, so even large files do not freeze the page, and your code is processed locally.
- Mangle variable names: shortens local names. Names that are exported or used as object properties are left alone.
- Compress: enables Terser's optimisations, two passes.
- Remove console.* calls: strips debug logging from production builds.
- Keep license comments: preserves comments marked
/*! ... */or containing@license. - Treat as ES module: enables strict mode and top-level optimisations. Turn it off for classic scripts that rely on top-level
varglobals.
Worked example
Input (197 characters):
// Greets a user
function greet(userName, greeting) {
const message = greeting + ", " + userName + "!";
console.log(message);
return message;
}
export const result = greet("world", "Hello");
Output with default options (82 characters):
export const result=function(){const o="Hello, world!";return console.log(o),o}();
Comments and spaces disappeared. Because greet is only called once with fixed arguments, the minifier inlined it and joined the string ahead of time, renamed the local variable to o, and merged the last two statements. The exported name result is untouched, because renaming it would break importers.
Before you ship
- Keep the readable source in version control and treat the minified file as a build artifact. Debugging minified code is painful without a source map; bundlers generate those for you.
- Code that relies on
Function.prototype.toString, or on function names for logic, can break when names are mangled. - On gzip or Brotli-compressed hosting, minification still helps, typically by another 20 to 40 percent over compression alone.
- To make minified code readable again, use the JavaScript beautifier.
Frequently asked questions
Is my code sent to a server?
No. Terser is bundled into this page and runs in a Web Worker inside your browser. Nothing is uploaded, which makes it safe for proprietary code.
Why did minification fail with a syntax error?
Terser only accepts valid JavaScript. The message includes the line and column. If your code uses import or export, keep the module option on; if it uses top-level return from an old script, turn it off.
Does it support modern syntax such as optional chaining and classes?
Yes. Terser understands current ECMAScript, including classes, async functions, optional chaining, nullish coalescing and modules. It does not compile TypeScript or JSX, so transpile those first.
Is minified code the same as obfuscated code?
No. Minification aims for smaller size. Mangled names make code harder to read, but it is not a security measure and can be reversed with a beautifier. Do not rely on it to protect secrets.