RevealTheme logo

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. 1

    Paste or type your JavaScript into the input textarea.

  2. 2

    The minified output appears instantly in the panel below as you type — there is no button to press.

  3. 3

    Check the size readout (original length, an arrow, and minified length) to see how much was removed.

  4. 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?
It can break valid, everyday code. Because it does not understand strings, any // inside a string or template literal (for example a URL like https://example.com) is treated as a comment and the rest of that line is deleted. Whitespace inside strings is also collapsed. Only minify code with no slashes or meaningful spacing inside string and regex literals.
How does this compare to Terser or esbuild?
Terser, esbuild, and SWC parse your code into a syntax tree before transforming it, so they never corrupt string contents and they also mangle variable names and remove dead code. They commonly reach 60-80% size reduction. This tool only strips comments and collapses whitespace, so it is both less safe and far less effective.
Why is the output not much smaller than the input?
Whitespace runs are reduced to a single space rather than removed entirely, and there is no name mangling or dead-code elimination. So a + b stays a + b, and identifier and structure overhead remains. The savings come almost entirely from removed comments and indentation.
Does it remove console.log or unused variables?
No. There is no dead-code elimination, tree-shaking, or any semantic analysis. Every statement you paste, including debugging calls and unused declarations, is preserved verbatim in the output.
Is the byte count exact?
It is approximate. The readout uses JavaScript string length, which counts UTF-16 code units, and labels them bytes. For ASCII that matches the UTF-8 byte size, but characters outside the basic range (such as emoji or many non-Latin scripts) will make the true byte count differ.
Is my code uploaded anywhere?
No. Everything runs locally in your browser using simple string replacement. Your JavaScript is never sent to a server, so it is safe to paste private or proprietary code.

Related tools