Skip to main content

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.

JavaScript Input
0 chars
Minified JavaScript
0 chars

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

  1. Paste your JavaScript into the JavaScript Input panel, or click Example to load a sample script.
  2. The Minified JavaScript output updates instantly — there is no Minify button to press.
  3. Read the stats bar above the output for original size, minified size, and the exact percent saved.
  4. Click Copy to put the minified code on your clipboard, or Download to save it as toolk-minified.js.
  5. 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.

TransformThis Toolk minifierAST tool (Terser)
Line & block commentsRemovedRemoved
Whitespace & blank linesRemovedRemoved
Spaces around operatorsCollapsedCollapsed
Identifier / variable manglingNot doneDone
Dead-code eliminationNot doneDone
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.

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.

Need a different tool?

Browse all 103 browser-based tools (103 currently marked free), or tell us what useful utility we should build next.

Browse all tools