JavaScript Minifier guide
Shrink JavaScript for embeds, bookmarklets, inline scripts, and quick experiments. The minifier tokenizes your code, so strings, regular expressions, and template literals stay intact, and line breaks are kept wherever removing them could change behavior.
Why a regex minifier breaks code
The quick way to minify JavaScript is a few regular expressions: delete everything after //, collapse whitespace, squeeze spaces around operators. It looks fine on a toy example and breaks on real code. The // in "https://example.com" gets treated as a comment. The spaces inside "Hello world" collapse. A regex literal like /\/\*/ confuses the comment stripper. And collapsing every line break into nothing destroys code that relies on automatic semicolon insertion.
This minifier avoids all of that by tokenizing: it walks the source character by character and recognizes strings, template literals (including nested ${} expressions), regular expressions, comments, numbers, identifiers, and operators. Only the gaps between tokens are touched. Everything inside a token is copied exactly.
The rules it applies
Comments are removed. Between two tokens, whitespace is dropped entirely unless one of three things is true. First, both sides are word-like, as in return value or let x, so a single space is needed. Second, dropping the space would merge operators, such as a - -b becoming a--b, or a + ++b becoming a+++b; a space is kept. Third, the whitespace contained a line break and removing it could change how automatic semicolon insertion works; then the line break is kept.
The ASI check is conservative. A line break is dropped only if the token before it is an operator that cannot end a statement (like =, (, or ,), or the token after it cannot start one (like ), ., or ?). Everywhere else, the newline stays. You give up a few bytes and never ship a subtle bug.
Worked example: why ASI matters
Take three lines: let c = a, then ++b, then log(a, b, c). With no semicolons, JavaScript reads that as let c = a; ++b; log(...), because a line break before ++ triggers semicolon insertion. A naive minifier that joins lines produces let c=a++b, which no longer means the same thing and is in fact a syntax error. This tool outputs let c=a, a line break, then ++b, preserving the original meaning.
Another classic: return on its own line followed by a value on the next line. JavaScript inserts a semicolon right after return, so the function returns undefined. The minifier keeps that line break, so the minified code behaves identically, bug included. Minifiers should never fix or change behavior; that is a linter's job.
On the sample loaded in the tool, a small commented function, output shrinks by roughly 30% to 40%. On heavily commented library code, savings of 50% or more are common before gzip.
Minification vs. compression vs. bundling
Minification removes unneeded characters. Mangling, done by Terser, esbuild, and SWC, goes further and renames local variables to single letters and removes unreachable code. Gzip or Brotli compression, applied by your server or CDN, then compresses the text for transfer. They stack: a typical library might go from 100 KB to 40 KB minified and mangled, then to around 12 KB over the wire with Brotli.
For production apps, let your bundler handle all of this: Vite, webpack, Next.js, and Astro minify automatically in production builds. A standalone minifier is for everything outside that pipeline: a snippet for a CMS embed, a script tag for a landing page builder, a bookmarklet, a Google Tag Manager custom HTML tag, or quickly checking how small some code gets.
Limits and mistakes to avoid
It does not parse JavaScript into a full syntax tree, so extremely unusual code, such as a regex literal directly after a closing parenthesis on the same line, may be misread. If the output looks wrong, the status line flags syntax it cannot tokenize, like an unterminated string. Test minified code before shipping it, as you would with any build step.
Do not minify code you still need to edit: keep the readable source in version control and minify a copy. Do not strip license headers the license requires. And do not paste proprietary code or API keys into online tools that store or share submissions; this one runs in your browser and sends nothing anywhere.
How we calculate: sources
Frequently asked questions
What does a JavaScript minifier do?
It removes characters the engine does not need: comments, indentation, and most spaces and line breaks. The code runs the same but downloads faster. This tool typically cuts well-commented code by 30% to 50%.
Is it safe for code without semicolons?
Yes. JavaScript's automatic semicolon insertion (ASI) depends on line breaks, so the minifier keeps a line break wherever removing it could change meaning, for example between count++ and the next statement, or after return.
Will it break strings, regex, or template literals?
No. It reads the code as tokens, so spaces inside strings, // inside URLs, slashes inside regular expressions, and whitespace inside template literals are preserved exactly.
Does it rename variables like Terser or UglifyJS?
No. It only removes comments and whitespace. Tools like Terser and esbuild also shorten variable names and remove dead code, typically saving more. Use them in your build pipeline for production bundles.
Can I paste proprietary code here?
Yes. Minification runs entirely in your browser; the code is never uploaded, stored, or shared. Online formatters with save-and-share features have exposed users' pasted secrets before, so a local tool is the safer habit.
Should I remove license comments?
Keep them if the license requires it. MIT, BSD, and Apache-licensed code generally require the copyright notice to stay with the code. This tool removes all comments, so re-add the license header after minifying.
Is my code uploaded?
Everything runs in your browser. Nothing you enter is uploaded to a server or stored by us.
Does minified JavaScript run faster?
Mostly it downloads and parses faster. Execution speed is about the same, since engines compile the code either way. The real win is fewer bytes over the network, especially on mobile connections.
Can minified code be un-minified?
Formatting can be restored with any beautifier, but comments are gone for good, and if a tool like Terser renamed variables, the original names cannot be recovered without a source map.