JavaScript ships as text, and text ships with padding: comments explaining old bugs, indentation marking nesting, line breaks between statements, and blank lines separating sections. None of it executes. A minifier deletes the padding while leaving the program's behavior untouched, and this tool performs that pass live in your browser, with the before and after byte counts shown beside the output so the saving is a number you can put in a commit message.
Two transformations are applied. Comments are removed, including line comments and block comments. Whitespace between tokens that carries no meaning, such as indentation, line breaks, and runs of spaces, is collapsed. Strings are recognized before either pass runs, so a comment-like sequence inside a quoted string survives intact, and a space inside a string is never touched. Operators, identifiers, numbers, and punctuation are left exactly as written: no renaming, no reordering, no semantic rewriting of any kind.
The tool runs locally; scripts containing business logic, API keys, or customer-handling code never leave your device. It is free, requires no signup, and works on mobile.
Before and After: Realistic Numbers
Savings depend on how the source was written. A commented, well-indented script saves the most; output from a build pipeline that already strips whitespace saves little. Representative examples:
| Script | Before | After | Saved |
|---|---|---|---|
| Hand-written utility library, comments and 2-space indent | 45,000 bytes | 28,000 bytes | 38 percent |
| Widget script with license header and dense comments | 12,600 bytes | 8,100 bytes | 36 percent |
| Already compact bundle, minimal comments | 88,000 bytes | 82,300 bytes | 6 percent |
The illustrative 45,000-to-28,000-byte row is the honest middle case: a source file written for humans, with a comment on most functions, typically loses about a third of its bytes, and comments plus indentation account for nearly all of it. The third row shows the ceiling of the technique: if the input is already whitespace-light, a whitespace-and-comment minifier has little left to take, which is expected rather than a defect.
An honest caveat about what real production minifiers do beyond this: tools like Terser also rename local variables to one or two characters, fold constants, drop dead code, and rewrite expressions into shorter equivalents. Variable renaming alone often saves another 15 to 25 percent on unminified code, and those transformations require a full parser plus a tested build pipeline, because a wrong rename breaks the program. This tool deliberately performs only the provably safe subset: comments and whitespace out, everything else untouched, so the output always behaves identically to the input.
How Strings and Comments Are Protected
The parser that drives the minifier classifies every character into three worlds: inside a string, inside a comment, or in code. Minification decisions apply only in the code world. A quoted string containing two slashes in a row, which looks exactly like a line comment, stays whole because the string classification wins. A string containing newlines or multiple spaces keeps them, since spaces inside strings are data, not padding. Comments, conversely, are removed entirely wherever they legally occur, including comment blocks between statements and trailing line comments after code.
| Input element | Treatment | Reason |
|---|---|---|
| Line and block comments | Removed | No effect on execution |
| Indentation and line breaks between tokens | Removed or collapsed | Whitespace between tokens is meaningless |
| Spaces inside string literals | Preserved exactly | String content is data |
| Comment look-alikes inside strings | Preserved | The string context outranks the pattern |
| Identifiers and operators | Preserved exactly | No renaming or rewriting |
One whitespace subtlety deserves its own mention: a line break between two tokens is not always meaningless, because JavaScript's automatic semicolon insertion rules make some line breaks significant. The minifier only removes line breaks in positions where removing them cannot merge two statements, so code that relies on standard statement structure minifies safely. Code written with deliberately omitted semicolons in risky positions can behave differently when minified by any tool; the reliable practice is to include semicolons in source that will be minified.
How to Use the Minifier (Step by Step)
- Paste the script you want to compact. Minification runs live, and the byte savings appear with the result.
- Check for comments you need to keep, especially license headers, which are removed like all comments. If attribution requires one, paste a single header comment back at the top of the output.
- Copy the minified script into your deployment artifact or inline script tag.
- Keep the readable original in source control and re-minify at each deploy; never edit the minified file by hand.
The Deployment Workflow and Source of Truth
The pattern that avoids every classic minification accident is two versions: a formatted master that humans edit and a minified artifact that machines deploy. Hand-editing minified JavaScript is where bugs breed, because a missing comma in a long unbroken line is nearly invisible during review and a mistyped identifier breaks at runtime rather than in the diff. If you receive minified code that needs a change, run it through the paired beautifier first, edit the readable version, and minify again.
License compliance is the one place where minification and legal requirements meet. Most open-source licenses require keeping copyright and license notices with the code. Since this tool removes all comments, re-add the required header to the top of the minified output as a single comment line, which costs bytes only once per file, or maintain a separate attribution file as many build tools do.
Minification, Compression, and What Stacks
Minification is the first layer of a two-layer pipeline. Server compression, gzip or Brotli, is the second, typically removing another 70 to 80 percent of whatever remains on the wire. They stack because compression works on repetitive bytes and minified code is repetitive in a different way than formatted code. The two layers together are why a 45,000-byte source file might reach a visitor as roughly 6,000 bytes of transfer: about 17,000 bytes removed by minification and the remainder compressed by the server.
Tips and Best Practices
- Minify from a readable master at deploy time, and never edit minified output directly.
- Include semicolons explicitly in scripts destined for minification; do not rely on automatic insertion in risky positions.
- Re-add license headers to minified output when a library's license requires the notice to ship with the code.
- Test the minified script in a staging environment before shipping; behavior should be identical, and a smoke test proves it.
- Use the byte report to audit whether a deployed script was actually minified; large savings mean it was not.
- Pair with server compression and caching headers for the full performance effect; minification is one layer of three.