JavaScript Minifier

Strip comments and redundant whitespace from JavaScript safely — preserving strings, templates, regex, and line breaks — and see the size saved. Runs entirely in your browser.

Minified 154121 bytes (21.4% smaller)

function greet(name) {
const url = "https://example.com";
const re = /\s+/g;
return `Hello, ${name.replace(re, " ")}!`;
}

Conservative minification: strips comments and redundant whitespace while preserving line breaks (so semicolon-insertion behavior is unchanged) and all string/template/regex contents. For maximum compression (variable mangling, dead-code removal) use terser or esbuild in your build pipeline.

About this tool

This is a conservative, dependency-free JavaScript minifier that runs in your browser. It removes line and block comments and collapses redundant whitespace, while being careful in exactly the ways that matter for correctness: it preserves a line break wherever the original whitespace crossed lines, so automatic semicolon insertion (ASI) behaves identically; it never merges two tokens together; and it leaves the contents of string literals, template literals, and regular expressions completely untouched — including tricky cases like a // sequence inside a URL string or an escaped slash inside a regex. The result is smaller code that behaves the same. What it deliberately does not do is the heavy, AST-level work of a production minifier — renaming variables, removing dead code, folding constants — because doing that safely requires a full parser. For maximum compression in a real build, run terser or esbuild; for a quick, safe shrink of a snippet, this is ideal. Everything happens locally, so your code is never uploaded.

How to use it

  • Paste your JavaScript.
  • Read the minified output and the size reduction.
  • Copy it for a quick inline use or a snippet.
  • For production bundles, use terser/esbuild — this is a safe lightweight pass, not a full optimizer.

Frequently asked questions

Is the minified code guaranteed to behave the same?
It is designed to: comments and redundant spaces are removed, but line breaks that could affect automatic semicolon insertion are preserved, tokens are never merged, and strings/templates/regex are left byte-for-byte intact. It is a conservative transform, not an aggressive rewrite.
Why is it not as small as terser output?
Terser and esbuild parse the code into an AST and then rename variables, drop unreachable code, and fold constants — large savings that require fully understanding the program. This tool only strips comments and whitespace, which is safe without a parser but compresses less.
Does it handle regex and template literals correctly?
Yes. It tracks context to tell a regex literal from a division operator, copies regex (including character classes and escaped slashes) verbatim, and preserves template literals and their ${...} expressions exactly.
Will a // inside a string be mistaken for a comment?
No. String and template contents are detected and copied untouched, so a URL like "http://example.com" or any // inside quotes is never treated as a comment.
Should I use this in my build pipeline?
For real builds, use a proper minifier (terser, esbuild, SWC) integrated with your bundler — they compress far more and are battle-tested. Use this for one-off snippets, inline scripts, or when you want a safe quick shrink without tooling.
Is my code uploaded?
No. Minification runs entirely in your browser with no network request, so proprietary code stays on your machine.

Related tools