JavaScript Minify — Compress JS Online with Terser
🔒 Runs in your browser — nothing is sent to a serverJavaScript 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.
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
function greet(name) {
if (name) {
return "Hello, " + name + "!";
} else {
return "Hello, World!";
}
}
const sum = (a, b) => a + b;
export { greet, sum };function greet(n){return n?"Hello, "+n+"!":"Hello, World!"}const sum=(n,e)=>n+e;export{greet,sum};const DEBUG = false;
function track(event) {
if (DEBUG) {
console.log("track:", event);
}
sendBeacon(event);
}
function sendBeacon(e) { navigator.sendBeacon("/log", JSON.stringify(e)); }function track(n){sendBeacon(n)}function sendBeacon(n){navigator.sendBeacon("/log",JSON.stringify(n))}const tool = "javascript minify";
const useCase = "compress js for production";
export const meta = { tool, useCase, online: true };const tool="javascript minify",useCase="compress js for production";export const meta={tool:tool,useCase:useCase,online:!0};/*! Acme Lib v1.2.0 | MIT */
// internal: counter helper
let count = 0;
export function increment() { count = count + 1; return count; }/*! Acme Lib v1.2.0 | MIT */let count=0;export function increment(){return count=count+1,count}