JavaScript Minifier
Strip comments and collapse whitespace from JS in your browser.
Written by Golam Rabbani, Founder & Lead Engineer
How to use this javascript minifier
- Paste your JavaScript source into the input box.
- Press Minify to strip comments and collapse whitespace.
- Compare the original and minified byte counts in the result header.
- Copy the minified code or hit Reset to clear and start over.
About this javascript minifier
The JavaScript minifier walks your source token by token. It drops both line and block comments, collapses every run of whitespace, and removes the spaces around punctuation that the parser does not need. Strings, template literals, and regular-expression literals are detected and preserved character-for-character so escape sequences and embedded expressions survive unchanged. The minifier deliberately avoids renaming variables or doing dead-code elimination — those are the jobs of a full compiler like esbuild or Terser, and they require a complete parse of your bundle, not a single snippet.
The result is a safe, conservative byte-saver: typical inputs shrink by 30-60% compared to the formatted source, and the savings compound after gzip because long whitespace runs and comment paragraphs were already very compressible. Use it for hand-written script tags, inline snippets in HTML emails, code golf challenges, or whenever you need a quick byte-count comparison without spinning up a build pipeline.
For example, the input "function add(a, b) { // sum two numbers\n return a + b;\n}" minifies to "function add(a,b){return a+b;}" — 56 bytes down to 28 bytes (50% smaller), with no behavioural change.
FAQ
- Will it break my code?
- It only removes whitespace and comments and preserves strings, templates, and regex literals exactly. As long as your code is syntactically valid going in, the output is equivalent. It does not perform aggressive transforms that change semantics.
- How does it compare to Terser or esbuild?
- Terser and esbuild rename variables, drop dead code, and inline constants for much higher savings — but they need a real parser and a build step. This tool is a quick paste-and-go helper that gives you most of the whitespace savings without any setup.
- Is the gzipped estimate accurate?
- The displayed gzip number is a rough estimate (~35% of the raw byte size) that matches what real gzip output usually achieves for minified JS. For a precise figure, run the output through gzip on the command line.
- Does it support ES2020+ syntax?
- Yes. The tokeniser handles modern syntax including optional chaining, nullish coalescing, template strings with embedded expressions, and BigInt literals because it only cares about lexical token boundaries.
- Is my code uploaded?
- No. Minification runs entirely in your browser.
- Why is my regex literal still there?
- Regex literals are preserved so search patterns keep working. The minifier identifies them by context (a / after operators or keywords like return) so divisions are not confused for regexes.