JavaScript Minifier for Code Snippets
Reduce supported JavaScript whitespace and comments in a pasted snippet. Review the output and its behavior before including it in a project.
JavaScript Minifier workspace
This text-based minifier can change JavaScript behavior. Keep the original and test the output before use; use a parser-based build tool for production code.
Instant Processing
Minify your JavaScript in real-time as you paste or type code.
Size Reduction
See exactly how many bytes you save with detailed compression statistics.
Local input processing
All processing happens locally. Your code never leaves your browser.
JavaScript Minifier: Compress JS by Stripping Comments and Whitespace
Reduce supported JavaScript whitespace and comments in a pasted snippet. Review the output and its behavior before including it in a project. This browser utility is not a replacement for a parser-based production build pipeline. JavaScript syntax, automatic semicolon insertion, and regular-expression literals can make text-based rewriting unsafe. Test the transformed code and retain the original source.
How to use the JavaScript minifier
- Paste your JavaScript into the JavaScript Input panel, or click Example to load a sample script.
- The Minified JavaScript output updates instantly — there is no Minify button to press.
- Read the stats bar above the output for original size, minified size, and the exact percent saved.
- Click Copy to put the minified code on your clipboard, or Download to save it as
toolk-minified.js. - Use Clear (the trash icon) to reset both panels and start over.
How JavaScript minification works
Minification reduces file size without changing behavior. Across most real-world bundles, whitespace removal and identifier mangling account for roughly 95% of the savings — not exotic code transforms. Production tools such as Terser parse your code into an Abstract Syntax Tree, then mangle local variable names, fold constants, and run dead-code elimination, reaching reductions up to about 80%.
This Toolk minifier is the lightweight, browser-side tier of that pipeline. It performs safe textual minification only: it deletes // line comments and /* */ block comments, removes blank lines and indentation, collapses repeated spaces and tabs, and strips most spaces around operators — while preserving the spaces that keywords like return, typeof, and const require. It does not rename variables or remove unused code, so the output stays recognizable.
"Minification removes whitespace, comments, and redundant characters while variable names stay the same; uglification goes further by renaming variables and functions to the shortest possible names."— The distinction this tool follows: it minifies, it does not mangle.
One detail build tools add that this one removes: a source map comment. Bundlers append a //# sourceMappingURL=app.js.map line so DevTools can map minified code back to your source (see the MDN source map glossary). Because this minifier strips all comments, any sourceMappingURL or /*! license */ banner is removed too — add those after minifying.
Worked examples: input → output
Comment + whitespace removal
// add two numbers function add(a, b) { return a + b; }
→ function add(a,b){return a+b;}
Block comment dropped
/* config */ const MAX = 100;
→ const MAX=100;
Edge case · comment marker inside a string
The comment stripper is regex-based, not a parser. A // inside a string literal — for example const note = "visit example.com // now"; — gets cut from // onward, breaking the string. A leading https:// is protected (the regex skips // after a colon), but other in-string or in-regex // sequences are not. Review output that contains // inside strings or regex literals.
What this minifier does — and what it leaves alone
These rows reflect the actual transforms in this tool, contrasted with a full AST compressor like Terser. Use it to decide whether browser-side minification is enough or you need a build step.
| Transform | This Toolk minifier | AST tool (Terser) |
|---|---|---|
| Line & block comments | Removed | Removed |
| Whitespace & blank lines | Removed | Removed |
| Spaces around operators | Collapsed | Collapsed |
| Identifier / variable mangling | Not done | Done |
| Dead-code elimination | Not done | Done |
| Typical raw size cut | ~20–60% | up to ~80% |
Minification and Gzip/Brotli are not the same job
Minifying is not a substitute for server compression — the two stack. Minification rewrites the source to fewer bytes; Gzip and Brotli then compress those bytes in transit and the browser decompresses them. Minified JavaScript actually compresses better, because there is less redundant whitespace for the algorithm to encode. In practice, minify + Brotli (or Gzip) can shrink a payload by roughly 80–90% versus the original source, and Brotli typically beats Gzip by about 15–20%.
Practical takeaway: use this tool for quick, transparent comment-and-whitespace minification, keep server compression on, and reach for a build-time AST tool only when you need identifier mangling or dead-code elimination. The savings figure shown here is raw bytes (measured as the UTF-8 Blob size), so your over-the-wire number after Brotli will be smaller still.
Related developer & web tools
Shrink stylesheets the same way
HTML FormatterTidy and indent messy markup
JSON FormatterValidate and pretty-print JSON data
HTML to JSXConvert HTML into React JSX
HTML Entity ConverterEncode and decode HTML entities
Image CompressorCut image weight for faster pages
Token CounterCount LLM tokens in your code
Markdown TOCBuild a table of contents fast
Meta Tag PreviewerPreview SEO and social tags
Open Graph GeneratorGenerate OG meta tags
Favicon GeneratorCreate favicons in every size
Word CounterCount words and characters
All ToolsBrowse the full Toolk toolbox
Last updated: September 15, 2026 · Runs 100% in your browser — no uploads, tool input is not sent to Toolk.
Frequently asked questions
Does this minifier rename variables or drop dead code?
No — and that is deliberate. It is a comment-and-whitespace minifier, not an AST transformer: identifiers keep their names and unreachable branches stay in place, so behavior is predictable without a source map. For mangling and tree-shaking, use a build-time tool such as Terser or esbuild.
Can minifying ever break working code?
It can, rarely. Because the engine is regex-based rather than parser-based, a comment marker inside a string or regex literal can be mistaken for a real comment, and spacing changes around / can affect regex literals. Always test the output before shipping anything critical.
Is my source code uploaded while minifying?
No. The transformation runs locally in your browser tab, and Toolk’s page analytics do not receive your code or the output. Unreleased work stays on your device, and minification keeps working offline once the page has loaded.
How much smaller will my file get?
Typically 20–40% for readable source, depending on comment density and indentation style. That is real bandwidth savings on cached assets, though far short of what an AST minifier with mangling achieves — the two approaches complement each other.
What is the safest workflow before deploying minified JS?
Keep your readable original as the canonical version and treat the output as disposable. If you also ship stylesheets, run Toolk’s CSS Minifier (/tools/css-minifier) over them in the same pass so both asset types go out consistently compressed.