← All tools
// Code

JavaScript Minifier online

Minify JavaScript to reduce file size or beautify JS for readability

JavaScript Minifier logo
by
CHUNKY
MUNSTER
// Input JavaScript
0
Input bytes
0
Output bytes
Saved
// Minified output
Output will appear here...

How to Use the JavaScript Minifier

  1. Paste your JavaScript into the input panel.
  2. Click Minify to run the comment-strip and whitespace-collapse passes.
  3. Read the input bytes, output bytes and percent-saved figures below the buttons.
  4. Use Download .txt to save the minified output, or copy directly from the output panel.

This is a deliberately small JavaScript minifier. It takes one regex pass to drop /* … */ block comments and // line comments, then a second pass to collapse runs of whitespace and trim it from around common operators and punctuation. That is enough to shave 20–40% off most hand-formatted snippets without bringing in a parser or running anything on a server.

How the JavaScript Minifier Works

What it does not do matters too. There is no AST, so no variable renaming, dead-code elimination or semicolon insertion fixes. Regex literals containing // and template literals with intentional whitespace can occasionally be mangled — always test the output. For production builds, reach for Terser, esbuild or SWC, all of which run on a parsed AST and preserve semantics correctly.

Frequently Asked Questions

Is this a real minifier like Terser or esbuild?

No. It is a fast regex-based pass that strips comments and collapses whitespace — useful for quick prototyping or shaving a few bytes off a snippet. For production code use Terser, esbuild or SWC, which understand the AST and can rename variables, remove dead code and preserve semantics around regex literals and template strings.

Will it break my code?

It can. Because there is no parser, edge cases like a regex literal containing // or a template literal with significant whitespace can be mangled. Always test the output in a browser before shipping it, or run a real minifier.

Why doesn't it rename variables?

Variable renaming requires scope analysis from a real parser. This tool deliberately does the cheapest 80%-of-the-savings transforms only — strip comments, drop whitespace — so it stays small and predictable.

What does the percent saved figure measure?

TextEncoder().encode(...).length on the input and output, so it is real UTF-8 byte size — the same number gzip will see before compression. Gzip usually compounds the saving by another 60–80%.

Explore the full suite of Code tools and 290+ other free utilities at Chunky Munster.