JavaScript Minifier

Shrink JavaScript files by stripping comments and whitespace.

This is a safe whitespace/comment minifier — it does not rename variables, so your code's behaviour is unchanged. Strings, regexes and template literals are preserved.

What Does the JavaScript Minifier Do?

The JavaScript Minifier reduces script file size by stripping comments and collapsing unnecessary whitespace — safely. It tokenizes your code rather than blindly deleting characters: string literals, template literals and regular expressions pass through completely untouched, and newlines that JavaScript's automatic semicolon insertion (ASI) depends on are preserved, so the minified code behaves exactly like the original.

Unlike aggressive bundler minifiers, this tool deliberately does not rename variables or restructure logic. That makes it dependency-free and guaranteed safe for any script, at the cost of a somewhat smaller compression ratio — typically 15–35% depending on comment density.

How to Minify JavaScript

  1. Paste your script into the left box.
  2. Click Minify JavaScript.
  3. Review the size report, then copy the output or download script.min.js.

What Gets Removed — and What Doesn't

  • ✅ Removed: // line comments, /* block comments */, indentation, blank lines, spaces around operators.
  • 🔒 Preserved: everything inside "strings", 'strings', `template literals` and /regex/ literals.
  • 🔒 Preserved: newlines whose removal could change ASI behavior (e.g. before a line starting with ( or [).
  • 🔒 Preserved: variable names, function names, code structure — debugging stays feasible.

Use it for handwritten site scripts, quick fixes on legacy projects without build tooling, or to shrink inline scripts in HTML emails and landing pages.

Frequently Asked Questions

Is this minifier safe for any JavaScript?

Yes — because it only removes comments and provably insignificant whitespace, and never touches strings, regexes or identifiers, the minified code is functionally identical. It is the conservative counterpart to renaming minifiers like Terser.

Why is my compression lower than tools like Terser?

Terser also shortens variable names and rewrites expressions, which requires a full parser and can occasionally change edge-case behavior. This tool trades a few percent of compression for guaranteed safety and zero configuration.

Does it handle template literals with ${expressions}?

Yes. Backtick strings, including nested interpolation, are detected and passed through byte-for-byte.

Can minified code still be debugged?

More easily than fully-mangled code, since names survive. For serious debugging keep your original source — minification is for what you ship, not what you edit.