Aller au contenu
JS

JS Minifier/Beautifier

Beautify or minify JavaScript — comments and whitespace only, never breaks your code.

Original
218 B
Result
182 B
Reduction
−16.5%
/*! MyLib v1.0.0 | MIT License */ function greet(name) { const pattern = /^[a-z]+$/i; if (!pattern.test(name)) { return `Hello, stranger!`; } return `Hello, ${name}! Welcome.`; }

This tool only strips comments and whitespace — it never renames identifiers or rewrites your code. Newlines are always preserved to stay safe from ASI (automatic semicolon insertion). For maximum compression in production builds, use terser or esbuild.

À propos de JS Minifier/Beautifier

A JS minifier/beautifier formats JavaScript for reading (beautify) or strips whitespace and comments to shrink file size (minify). Real-world minifiers like terser or esbuild go further — renaming identifiers, eliminating dead code, rewriting expressions — but doing that correctly requires a full parser and scope analysis, and getting it even slightly wrong can silently break working code. toco.tools's JS minifier deliberately doesn't go that far. It only removes comments and whitespace: identifiers are never renamed, and the code's structure and expressions are never rewritten. It also specifically guards against JavaScript's ASI (Automatic Semicolon Insertion) hazard: wherever the original source had one or more newlines, the tool always preserves exactly one. Deleting a newline right after `return`, for example, can silently turn `return; x;` into `return x;` — instead of trying to detect every case where that's unsafe, this simple, bulletproof rule prevents it categorically. String literals, template literals (including `${...}` interpolation), and regular expression literals are preserved byte-for-byte, and bang comments (`/*! ... */`), commonly used for license headers, always survive minification. Being explicit about this tool's limits is the whole point — it's the trust signal. When you need maximum compression (identifier shortening, dead-code elimination) for a production build, reach for a real bundler-integrated minifier like terser or esbuild.

Comment l'utiliser

  1. Paste JavaScript
  2. Choose minify or beautify
  3. Check the ratio, copy the output

FAQ

How is this different from other JS minifiers?

It skips advanced optimizations like identifier renaming and dead-code elimination, focusing only on removing comments and whitespace — those deeper optimizations can't be done safely without a full parser. Being upfront about that limit is the trust signal.

Could removing newlines break my code?

No. JavaScript's Automatic Semicolon Insertion (ASI) means deleting a newline — right after `return`, for example — can change what the code does. This tool always preserves exactly one newline wherever the source had one or more, so this class of bug can't happen.

Does it rename identifiers for deeper compression?

No. Renaming identifiers or eliminating dead code safely requires full parsing and scope analysis, and a subtle mistake there can silently break your program. For maximum compression in a production build, use terser or esbuild.

Will my license comment be stripped?

Bang comments starting with /*! are preserved verbatim after minification. Ordinary comments (// and /* ... */) are removed.

Is my JavaScript sent anywhere?

No. Minification and beautification run entirely in your browser's JavaScript; nothing is sent to toco.tools's servers or anywhere else.