JavaScript Minifier
Strip comments and collapse whitespace in JavaScript, safely, without touching your logic.
How this tool works
Paste your JavaScript
A snippet or full file - strings and template literals are handled safely.
Character-by-character scan runs
Comments are removed while string and template literal contents are left completely alone.
Check the size comparison
Before/after byte counts show how much the whitespace and comment removal actually saved.
Copy the result
Grab the trimmed script - safe whitespace minification only, no renaming or logic changes.
Quick facts
- Category
- Formatters & Beautifiers
- Best for
- Trimming script size without a full build pipeline
About this tool
Paste JavaScript and get comments and extra whitespace removed while every string, template literal, and character inside them is left completely untouched - the minifier walks the source character by character rather than using blind regex substitution, so a "//" or "/* */" sequence sitting inside a string literal is never mistaken for a real comment. Before/after byte counts and a percentage reduction show the size savings. This intentionally does only safe whitespace-and-comment minification: it does not rename variables, eliminate dead code, or perform any AST-based transformation the way a build-time tool like Terser or esbuild would, so nothing here can change your code’s behavior. For maximum compression in a production build pipeline, a real bundler-integrated minifier is still the better choice - this is meant for quick one-off shrinking, not a build step replacement.
Why use this tool
String-literal aware
Walks the source character by character so a "//" inside a string is never mistaken for a comment.
Behavior-preserving
Only removes comments and whitespace - no variable renaming or dead-code elimination that could change behavior.
Honest about its scope
Clearly labeled as safe whitespace minification, not a Terser-level replacement - no surprises.
Instant, no bundler required
Useful for a quick size check without setting up esbuild or Terser for one file.
Frequently asked questions
No - this only strips comments and collapses whitespace, so the byte savings are smaller than what a full AST-based minifier achieves through variable renaming, dead-code elimination, and expression shortening. It’s meant for a quick size check or one-off cleanup, not as a replacement for the minifier in your actual build pipeline.
No - the minifier tracks whether it’s currently inside a quoted string or template literal as it scans the source, so sequences like "//" or "/*" that appear inside a string (e.g. a URL) are copied through unchanged rather than being treated as the start of a comment.
Explore more free tools
Formatters, converters, validators, and generators - all free and running entirely in your browser.
Browse more tools