Free JS Minifier & Beautifier
Compress JavaScript by removing comments and whitespace, or re-indent it for readability. Safely handles strings, template literals, regex and ASI.
Input JavaScript
/*! */ comments are always preserved.Output
What Is JavaScript Minification?
JavaScript minification removes every byte that JS doesn't need: comments, unnecessary whitespace, and redundant line breaks. The output runs identically, but downloads faster and parses quicker.
For a typical 100 KB JS bundle, minification alone cuts 15β40% of the size. That's meaningful for page load time β especially on mobile networks.
Minify vs Beautify
| Mode | Purpose | When to use |
|---|---|---|
| Minify | Remove whitespace and comments | Production deployment |
| Beautify | Re-indent code for readability | Debugging, code review, learning |
What gets removed
- Comments β
//line comments and/* */block comments are stripped, unless they begin with/*!. - Whitespace β spaces, tabs and newlines collapse to the minimum needed to keep tokens separated.
- Trailing semicolons β optional removal at the very end of the file.
What is preserved β and why it's hard
Naive minifiers break on three things that a real tokenizer must handle:
- Strings.
"hello // not a comment"β the//is inside a string, not a comment. - Template literals.
`${a + b}`β the${...}part is code, not text. Nesting requires brace matching. - Regex literals.
/abc+/gβ a/could start a regex or be division. The tokenizer distinguishes them by looking at the previous token: after an identifier, number or closing bracket,/is division. After operators, keywords likereturn, or at the start of an expression, it's a regex.
The ASI gotcha
JavaScript's Automatic Semicolon Insertion means a newline can act as a semicolon. This breaks naΓ―ve whitespace removal:
function getValue() {
return
5;
}
This function returns undefined, not 5 β the newline after return inserts a semicolon. A naΓ―ve minifier that collapses the newline produces return 5;, which changes behaviour.
This minifier preserves newlines after the ASI-sensitive keywords return, throw, break, continue and yield. All other newlines are collapsed safely.
What this tool does NOT do
- Variable renaming. Renaming identifiers from
longVariableNametoarequires building a full AST and tracking scopes. It saves more bytes but needs a real parser. For that, use Terser, esbuild or SWC. - Dead code elimination. Removing unused functions and constants needs static analysis.
- Constant folding. Computing
2 + 3at minify time requires evaluating expressions.
This tool does the safe 80% β whitespace and comment removal β using a proper tokenizer. That's what you need 90% of the time, and it never introduces bugs.
Common use cases
Production Deploy
Ship the smallest possible JS to every visitor.
Faster Page Load
JS is parser-blocking β smaller means faster time-to-interactive.
Debug Minified Code
Beautify minified libraries to understand what a dependency is doing.
Bookmarklets
Compress JS into a single line small enough for a bookmark URL.
Cleaner Diffs
Beautify before committing so Git diffs show real changes.
Email Snippets
Inline minified JS in email templates that have size limits.
Quick Snippet Prep
Minify a snippet before pasting it into a code-golf challenge.
Sanity Check
Run the output through the browser's parser to catch typos.
Privacy and security
This JS minifier runs entirely in your browser. A custom tokenizer walks the source character-by-character, strips unneeded bytes and re-emits the result β all in local JavaScript. Your code never leaves your device, safe for internal scripts, proprietary algorithms and unreleased work.
Frequently Asked Questions
What does a JavaScript minifier do?
Will minifying break my code?
Does it rename variables?
What about the ASI gotcha?
return\n5 returns undefined, not 5. This minifier preserves newlines after the ASI-sensitive keywords return, throw, break, continue and yield.Does it handle JSX, TypeScript, or ESM?
import / export) works, but the optional syntax check will report it as invalid because new Function() only validates function bodies, not modules.