JavaScript Minifier
A quick, in-browser JavaScript minifier that strips comments and collapses runs of whitespace to a single space. It is a naive text transform, not a parser — use Terser, esbuild, or SWC for production bundles.
How to use this tool
- 1
Paste or type your JavaScript into the input textarea.
- 2
The minified output appears instantly in the panel below as you type — there is no button to press.
- 3
Check the size readout (original length, an arrow, and minified length) to see how much was removed.
- 4
Select the text in the output box and copy it manually into your file.
What does this JavaScript minifier actually do?
Minification shrinks JavaScript so it downloads and parses faster, since the engine ignores comments and most whitespace. This tool performs three text substitutions with regular expressions: it deletes single-line comments (everything after // to the end of the line), deletes block comments (/* ... */), and collapses every run of whitespace — spaces, tabs, and newlines — down to one space, then trims the ends. It does not parse the code into an abstract syntax tree, so it has no understanding of strings, template literals, or regex literals. That has real consequences. A URL inside a string, such as 'https://example.com', contains // and gets truncated mid-string, breaking your code. Whitespace inside a string or template literal is also collapsed, mangling intentional formatting. And because runs are reduced to a single space rather than removed, tokens like a + b keep their spaces, so the savings are modest. There is no name mangling and no dead-code elimination. Real minifiers such as Terser, esbuild, and SWC tokenize the source first, so they preserve string contents while safely removing far more, typically reaching 60-80% reduction.
Common use cases
Quickly shrinking a short, comment-heavy snippet before pasting it into a tight inline <script> tag.
Stripping comments out of a code sample to share a compact version in a chat or gist.
Estimating roughly how much comment and whitespace overhead a small file carries before setting up a real build.
Cleaning up a hand-written configuration object or constant block that has no strings containing slashes.
Demonstrating to students or teammates what basic comment and whitespace removal looks like versus a real compiler.
Minifying a tiny utility function for a bookmarklet where pulling in a full toolchain is overkill.
Frequently asked questions
Will this break my code?▼
How does this compare to Terser or esbuild?▼
Why is the output not much smaller than the input?▼
Does it remove console.log or unused variables?▼
Is the byte count exact?▼
Is my code uploaded anywhere?▼
Related tools
JWT Decoder
Decode JSON Web Tokens (JWT) instantly — inspect the header, payload, and signature claims. Runs entirely in your browser; tokens never leave your device. Safe for production secrets.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Catches syntax errors with line numbers, pretty-prints with adjustable indent, supports large payloads. Runs in your browser — no upload.
XML Formatter & Beautifier
Format and beautify XML documents — proper indentation, line breaks, namespace handling. Useful for SOAP responses, sitemaps, RSS feeds, and Android resource files.
Base64 Encoder & Decoder
Encode and decode Base64 strings.
URL Encoder & Decoder
Encode/decode URL-safe strings.
HTML Entity Encoder & Decoder
Convert special characters to/from HTML entities.