Token-aware compression
JavaScript Minifier classifies the source into strings, templates, regexes, comments, operators, and identifiers before emitting the output. That ensures it never collapses whitespace that would change semantics.
JavaScript Minifier strips comments and unnecessary whitespace from JS while preserving every string, regex literal, and identifier, so your bundle shrinks without changing how the code behaves.
JavaScript Minifier is a free, browser-based tool that compresses JavaScript by removing comments and collapsing whitespace at safe boundaries. The output is functionally identical to the input — every browser and Node.js runtime executes the minified version the same as the original — but the byte count drops, which translates to faster downloads, faster parse times, and lower bandwidth usage.
JavaScript Minifier is token-aware. Strings, template literals, and regex literals are preserved verbatim so their contents are never touched, and the minifier inserts a single space between tokens only when removing whitespace would change meaning (for example, between two identifiers, or after a return that would otherwise trigger automatic semicolon insertion). You can toggle comment removal off if you need to preserve licence banners or build-tool markers.
Typical users are developers preparing a small inline script for embedding in a Next.js page, engineers shaving bytes from a critical-path script tag, and authors of standalone JavaScript widgets that ship to many sites. The tool is a fast way to evaluate compression savings before deciding whether to add a dedicated minifier to your build pipeline.
JavaScript Minifier classifies the source into strings, templates, regexes, comments, operators, and identifiers before emitting the output. That ensures it never collapses whitespace that would change semantics.
Comments are removed by default. A toggle lets you keep them when JSDoc, licence banners, or build-tool markers must survive in the output.
Quoted strings, template literals, and regular expressions are emitted byte-for-byte. The tool never alters values inside them, only the whitespace around them.
The minifier inserts a single space between tokens where removing whitespace would change parsing — for example, between two identifiers, or after a return statement. This protects against subtle automatic semicolon insertion bugs.
After each run, the tool displays input size, output size, and percentage saved. Use it to quickly judge whether minification is worth automating for your specific code.
All compression happens in your browser. Your scripts are never transmitted, which keeps proprietary code and prerelease modules confidential.
JavaScript engines tokenize the source into a sequence of identifiers, operators, literals, and punctuation. Most whitespace between those tokens is purely for human readers — the engine ignores it. JavaScript Minifier removes that whitespace while preserving the spaces that are semantically meaningful, such as the space between two identifiers in `const a` or after a `return` that triggers automatic semicolon insertion.
The biggest pitfall in a naive minifier is misreading a regex literal as a division. A slash inside source code can start a regex (after `return`, `typeof`, or an opening bracket) or denote division (after an identifier or closing paren). JavaScript Minifier resolves the ambiguity with a small lookback rule so regex literals are emitted verbatim instead of being broken apart.
Comments are the simplest savings target. Line comments end at the next newline, and block comments end at `*/`. Both are removed by default, but a toggle lets you preserve them when JSDoc or licence headers must survive. Pair minification with gzip or brotli on the server and the delivered payload shrinks further — minified code compresses smaller than verbose code.
Input
function add(a, b) {
// sum two numbers
return a + b;
}Output
function add(a,b){return a+b;}JavaScript Minifier is great for one-off jobs. For production sites, use terser, esbuild, or SWC in the build pipeline so every release benefits from rename-and-dead-code-elimination optimisations on top of whitespace removal.
Commit the readable version of scripts to version control so diffs are reviewable. Minify only as part of the build artifact, not the source files developers edit.
Many libraries require licence attribution even in minified files. Turn off comment removal so licence headers survive, or use a build tool that supports preserve hints.
Minification reduces the raw payload, but gzip and brotli compress further. The two stack, and minifying before compression typically produces the smallest delivered size.
Run your tests against the minified bundle, not just the source. Subtle automatic semicolon insertion or strict-mode interactions occasionally surface only after minification.
Those spaces are kept on purpose to avoid breaking automatic semicolon insertion or merging two identifiers into one.
Turn off "Remove comments" so licence and attribution headers survive minification.
Inline analytics and feature-flag scripts often ship with comments and indentation. JavaScript Minifier removes that overhead so the <head> stays compact.
Standalone widgets and bookmarklets ship without a build system. The tool provides a quick way to compress the JS before distribution.
JSDoc, TODOs, and reminder comments often survive into deployed bundles. Minifying removes them in one pass.
When JS is embedded inside JSON or HTML attributes, whitespace doubles the cost because of escaping. Minifying first keeps the surrounding payload small.
Before adding a minifier to a build pipeline, teams often want a quick estimate of the savings. This tool produces that number immediately.
Yes. JavaScript Minifier only removes whitespace and comments that the engine ignores at parse time. Strings, template literals, regex, and identifiers are preserved exactly, and a single space is kept where removing whitespace would change parsing (for example, between two identifiers).
Terser and esbuild are full production minifiers that also rename variables, fold constants, and eliminate dead code. This tool focuses on whitespace and comment removal — it is faster to run for one-off jobs and produces output that is easier to inspect, but the savings are smaller than what a full pipeline minifier produces.
Yes. Template literals (including embedded expressions), regex literals, arrow functions, async/await, optional chaining, nullish coalescing, and spread syntax all pass through unchanged.
It depends on the source. Heavily commented and indented code can shrink by 30–50 percent. Already-compact code may shrink less. The tool reports the exact byte savings after each run.
They are removed by default along with all other comments. Turn off comment removal if you need to preserve them, or use a build minifier with explicit preserve-comment hooks.
Yes. All compression runs in your browser. Your scripts are never uploaded, so internal code and prerelease modules remain confidential during the operation.
Yes, by running the output through JavaScript Beautifier on the same site. Round-tripping is safe as long as the input is valid JavaScript to start with.
Yes. Gzip and brotli compress repetitive text well, but minification removes bytes that compression would have to handle. The two techniques stack, and minifying before compression typically produces the smallest delivered payload.
JavaScript Minifier shrinks scripts without changing how they behave — use it to ship lighter inline JS, evaluate compression savings, and prepare standalone widgets without a build pipeline.