Developer Tools
JavaScript Minifier
Shrink JavaScript with a comment-stripping minifier that respects strings and regex.
Conservative minifier — always test the minified output before using it. For production builds, use Terser or esbuild.
Paste JavaScript and press Minify to see size savings.
What is a JavaScript minifier?
JavaScript minification shrinks a script by removing comments and unnecessary whitespace while keeping the program's behavior identical. This minifier is deliberately conservative: instead of renaming variables or restructuring code like production tools do, it runs a small state machine over the source that understands strings, template literals, regular expressions, and comments. That means a // inside a string is never mistaken for a comment, and a / starting a regex is never mistaken for division. The result is smaller, safe-to-test output — with a clear warning that production builds deserve Terser or esbuild.
How to use this tool
- Paste your JavaScript into the input box.
- Press Minify — comments are stripped and whitespace is collapsed wherever the state machine proves it safe.
- Check the size-savings card, then copy the output or download it as a .js file.
- Test the minified script in a browser or with node before deploying it anywhere.
Key features
- State-machine parser distinguishing code, line/block comments, single/double-quoted strings, template literals (including nested ${}), and regex literals.
- Smart regex-vs-division detection using the previous significant token and keyword context (return, typeof, and friends).
- ASI protection: newlines are preserved where joining lines could change semantics, such as after return or throw.
- Keeps required spaces (between identifiers, around ++/-- sequences) and drops everything else.
- Shebang lines (#!/usr/bin/env node) are preserved for CLI scripts.
- Size-savings report with copy and download, all processed locally in your browser.
Common use cases
- Quick size wins: shrinking a standalone script before embedding it in a page.
- Bookmarklets: compressing code that must fit in a bookmark URL.
- Email-safe scripts: reducing payload size for constrained environments.
- Learning: watching what a minifier actually changes (and does not change) in real code.
- Prototyping: a no-install minification step before setting up a proper build pipeline.
Practical tips
- Always run the minified output through your test suite or at least smoke-test it — minifiers can surprise you on edge-case syntax.
- This tool does not rename variables or remove dead code; for real production savings, use Terser, esbuild, or swc.
- Keep source maps in mind: debugging minified code without a map is painful, so generate maps in your build tool.
- Minification and gzip/Brotli stack — the smaller the input, the better compression works.
- If output behaves differently, the usual suspects are missing semicolons in the source or exotic syntax the simple state machine mishandles — file a note and use a full parser instead.
Frequently Asked Questions
Will minified JavaScript run exactly like my original?
It should — the minifier only removes comments and provably unneeded whitespace, and it protects strings, template literals, and regex. But 'should' is not 'guaranteed', so always test the output before production use.
How does it tell a regex apart from division?
It looks at the previous significant token: after (, =, return, and similar contexts a / starts a regex; after an identifier, number, or ) it is division. Keywords like return and typeof are recognized too.
Why are some newlines kept?
JavaScript's automatic semicolon insertion means joining certain lines changes behavior — return\nx must stay on two lines. The minifier keeps a newline wherever removing it could alter semantics.
Does it rename variables like Terser does?
No. This is a conservative whitespace-and-comment minifier only. Real production minifiers also shorten variable names, drop dead code, and need a full parser — use Terser or esbuild for that.
Is my code uploaded anywhere?
No. The state machine runs entirely in your browser, so proprietary or unreleased code never leaves your device.