JavaScript Minify — Compress JS Online with Terser

🔒 Runs in your browser — nothing is sent to a server

JavaScript minify any pretty-printed or hand-written script into the smallest valid representation in a single click. Paste a debug build, an ESM entry chunk, a hand-coded helper or any JavaScript blob, and this JS minifier runs the source through terser — the modern AST-based compressor that powers Webpack, Rollup and Vite — to strip whitespace, drop comments, eliminate dead code and squeeze conditional expressions. License comments (`/*! … */`, `/** @license … */`, `/** @preserve … */`) are kept; quote style, template literals and regex literals survive untouched. Variable mangling is opt-in. Everything runs 100% inside your browser; your input never leaves your device, nothing is uploaded, logged or sent to any server.

License comments (/*! … */, /** @license … */, /** @preserve … */) are always kept. Input limit: 1 MB.

Two-pane view: input and output side by side
Copied!

When to minify JavaScript online

You reach for an online JS minifier any time a script is about to travel across a constrained channel and you do not have a build pipeline handy: a one-off helper for a static site, a snippet pasted into a CMS template, a third-party widget being prepared for inline embedding, a serverless function shipping under a tight bundle limit, or a debug build you need to ship before the proper minifier in CI runs. Browser-local minification means the source never touches a remote server during the transform — important when the JavaScript contains internal admin logic, API keys baked into the bundle, A/B test code or unreleased product features you would rather not leak to a SaaS minifier.

How JavaScript minification with terser works

Terser is a parse-transform-emit pipeline that operates on the AST, not on regex text. The parser builds a full ECMAScript AST, recognising ES2020+ syntax (arrow functions, classes, optional chaining, async/await, template literals, regex literals). The compressor walks the tree applying dozens of passes: constant folding (`2 + 3` → `5`), conditional squeezing (`if (a) b(); else c();` → `a ? b() : c();`), dead-code elimination, joining sequential `var`/`let`/`const`, removing unreachable branches and inlining single-use functions. Optional mangling renames locals to single letters. The emitter prints the optimised AST back as JavaScript with no whitespace and no ordinary comments; license comments tagged with `/*!` or `/** @license */` are kept. The whole pipeline runs inside your browser via WebAssembly-free pure JS, so a typical page bundle minifies in milliseconds without leaving your tab.

Examples

Input
function greet(name) {
    if (name) {
        return "Hello, " + name + "!";
    } else {
        return "Hello, World!";
    }
}
const sum = (a, b) => a + b;
export { greet, sum };
Output
function greet(n){return n?"Hello, "+n+"!":"Hello, World!"}const sum=(n,e)=>n+e;export{greet,sum};
JavaScript minify — typical helper module compressed
Input
const DEBUG = false;
function track(event) {
    if (DEBUG) {
        console.log("track:", event);
    }
    sendBeacon(event);
}
function sendBeacon(e) { navigator.sendBeacon("/log", JSON.stringify(e)); }
Output
function track(n){sendBeacon(n)}function sendBeacon(n){navigator.sendBeacon("/log",JSON.stringify(n))}
Compress JavaScript — dead code eliminated, conditions squeezed
Input
const tool = "javascript minify";
const useCase = "compress js for production";
export const meta = { tool, useCase, online: true };
Output
const tool="javascript minify",useCase="compress js for production";export const meta={tool:tool,useCase:useCase,online:!0};
JS minifier — payload that names the tool itself
Input
/*! Acme Lib v1.2.0 | MIT */
// internal: counter helper
let count = 0;
export function increment() { count = count + 1; return count; }
Output
/*! Acme Lib v1.2.0 | MIT */let count=0;export function increment(){return count=count+1,count}
Minify JS — license header preserved, ordinary comments stripped

FAQ

How do I minify a JavaScript file in the browser?

Paste the JavaScript into the input above and click Minify. The JS minifier runs the source through terser — the same library Webpack, Rollup and Vite use under the hood — to strip whitespace, remove ordinary comments, eliminate dead code, squeeze conditionals and emit the smallest valid JavaScript that still runs identically. Input is capped at 1 MB to keep browser-side parsing fast.

What is JavaScript minification?

JavaScript minification rewrites a script with every byte of optional whitespace, every comment and every redundant construct removed, while the program runs identically. Terser also performs dead-code elimination, conditional squeezing, constant folding and other AST-level transforms. Minified JavaScript typically ships 30–70% smaller than its source; with mangling enabled, the saving climbs higher.

Why should I compress JavaScript before shipping it to production?

Smaller JavaScript means a smaller render-blocking payload, faster Time-To-Interactive, lower CDN egress, less battery drain on mobile and a higher Lighthouse score. Browsers apply gzip or Brotli on top of minified JS, and the two compound — minified-then-gzipped is materially smaller than gzipped-only. The win is biggest on slow networks, where every saved kilobyte cuts the parse-and-evaluate window.

What does "Mangle variable names" do, and is it safe?

Mangling renames local variables and parameters to single-letter names — `function calculateTotal(items)` becomes `function n(t)`. It materially shrinks the bundle but breaks any code that relies on `eval()`, `with`, `Function.prototype.name` or external callers passing argument names. Off by default; only enable it for code you fully control end to end. Top-level identifiers, exports and globals are left alone.

Does the JS minifier preserve license comments and `/** @preserve */`?

Yes. License comments — `/*! … */`, `/** @license … */`, `/** @preserve … */` — are kept by terser when configured with `comments: "some"`, which is the setting this minifier uses. Attribution, copyright headers and SPDX identifiers survive into the production bundle. Ordinary `//` and `/* */` comments are stripped because they have no semantic value at runtime.

How is JS minify different from JS beautify?

JS minify and JS beautify are exact opposites. Minify strips whitespace, removes comments and squeezes the AST to produce the smallest valid JavaScript for transport. Beautify adds line breaks and indentation back so a human can read and debug the code. Behaviour is identical in both directions; only cosmetic whitespace and (with mangling) variable names differ. Use minify for deploy, beautify for review.

Why is there a 1 MB input limit?

Terser does its work in a single AST pass, which is fast on small to medium inputs but expensive on multi-megabyte bundles when run inside a browser tab. Above ~1 MB the parse-and-emit slows noticeably and may stall the UI on weaker devices. For larger inputs use the terser CLI in a build step (`npx terser bundle.js -o bundle.min.js -c -m`) — it runs in Node where memory and CPU are not constrained.

Is it safe to paste proprietary JavaScript into this online JS minifier?

Yes — the minifier runs entirely in your browser via the terser library bundled into the page. Your source and the minified output stay on your machine; nothing is uploaded, logged or cached. Safe for unreleased product code, internal admin scripts, customer-facing helpers with embedded secrets and any JavaScript you would not want a remote SaaS minifier to retain.

Glossary

JavaScript minifier

A JavaScript minifier is any tool or function that compresses a script by stripping whitespace, removing comments, eliminating dead code and emitting the smallest valid JavaScript that still runs identically. Modern minifiers — terser, esbuild, swc — work on the AST, not on regex patterns, because ES syntax (regex literals, template literals, JSX) is too ambiguous to compress safely with text-level rewrites.

Terser

Terser is the de-facto modern JavaScript minifier — a fork of UglifyJS rewritten to support ES2015+ syntax (arrow functions, classes, optional chaining, async/await, private fields). It powers the Webpack production build, Rollup, Vite, Parcel and most other JavaScript build tools. Terser performs AST-level compression, mangling, dead-code elimination, conditional squeezing and constant folding.

Mangling

Mangling is the renaming of local identifiers — variables, parameters, sometimes properties — to single-letter names. `function calculateTotal(items)` becomes `function n(t)`. The transform is purely textual at AST level and is safe when no external code references the renamed identifiers. Terser mangles by default in build pipelines; this online tool keeps it opt-in because pasted snippets often have external callers.

Dead code elimination

Dead code elimination removes branches and statements that the minifier can prove will never execute — `if (false) { ... }`, code after an unconditional `return`, unused exports under terser `module: true`. The compressor walks the AST, evaluates constant expressions and drops unreachable paths. The result is smaller bundles and faster execution because the engine skips parsing dead branches.

License comment

A license comment is a JavaScript comment that opens with `/*!`, `/ @license` or `/ @preserve` — for example `/*! React v18.2.0 | MIT License */`. The marker is the convention shared by every modern JS minifier (terser, esbuild, swc) for "preserve this comment in the output". Terser respects the markers when configured with `comments: "some"`, which is what this minifier uses.

AST (Abstract Syntax Tree)

An AST is the tree representation of source code that compilers, linters and minifiers walk to perform their transforms. Terser parses JavaScript into an AST, applies dozens of optimisation passes (constant folding, conditional squeezing, dead-code removal) on the tree, then emits the final minified text. AST-based minification is safer than regex-based rewrites because it understands grammar context.

Related tools