Skip to content

JavaScript Minifier

Minified code —
Original characters
—
Minified characters
—
Size reduction
—
Comments removed
—
Literals kept as-is
—

Paste a script and the minifier removes comments, indentation and spaces between tokens, while strings, template literals and regular expressions are copied exactly. For example, var a = 1; // c followed by var b = 2; becomes var a=1;var b=2;, which cuts 27 characters to 16, a 40.7% reduction.

About this tool

A quick minify is handy when you inline a snippet into an HTML attribute, paste a bookmarklet, or want a rough idea of how much of a file is comments and indentation. This minifier reads the code token by token, so text that only looks like a comment, such as // inside a string or a URL in a regex, is left alone. It reports the original and minified character counts, the percentage saved and how many comments were dropped. Where a script relies on automatic semicolon insertion, it keeps the line break rather than guessing. It does not rename variables or remove dead code, so a bundler such as Terser or esbuild will still produce a smaller production file.

How to use it

  1. Add the script

    Paste JavaScript into the box or open a .js file from your device; it is read locally.

  2. Read the output

    The minified code appears as you type, with character counts and the size reduction beside it.

  3. Check any kept line breaks

    If a warning appears, the script has statements without semicolons and those breaks were kept on purpose.

  4. Copy the result

    Use Copy result to take the minified code into your page or file.

Examples

Two declarations with a comment

JavaScript code
var a = 1; // c var b = 2;

Result Minified code: var a=1;var b=2;
Original characters: 27
Minified characters: 16
Size reduction: 40.7%
Comments removed: 1
Literals kept as-is: 0

  1. Removed 1 comment and collapsed whitespace between tokens.
  2. Copied 0 string or template literals and 0 regex literals unchanged.
  3. Size: 27 → 16 characters (40.7% smaller).

The trailing comment and the spaces around = disappear, and the line break goes because a semicolon already ends the first statement.

A small function

JavaScript code
/* sum */ function add(a, b) { return a + b; }

Result Minified code: function add(a,b){return a+b;}
Original characters: 48
Minified characters: 30
Size reduction: 37.5%
Comments removed: 1
Literals kept as-is: 0

  1. Removed 1 comment and collapsed whitespace between tokens.
  2. Copied 0 string or template literals and 0 regex literals unchanged.
  3. Size: 48 → 30 characters (37.5% smaller).

The block comment, indentation and line breaks are removed; the space between function and add stays because both are words.

Comment-like text inside literals

JavaScript code
const s = "a // b"; const r = /\s+ x/g;

Result Minified code: const s="a // b";const r=/\s+ x/g;
Original characters: 40
Minified characters: 35
Size reduction: 12.5%
Comments removed: 0
Literals kept as-is: 2

  1. Removed 0 comments and collapsed whitespace between tokens.
  2. Copied 1 string or template literal and 1 regex literal unchanged.
  3. Size: 40 → 35 characters (12.5% smaller).

The // inside the string and the space inside the regular expression are part of the values, so both are copied unchanged.

How it is calculated

reduction % = (L₀ − L₁) ÷ L₀ × 100

L₀
length of the pasted source, including comments and whitespace
L₁
length after comments and removable whitespace are gone

The scanner walks the source once. Quoted strings, template literals (including ${} parts) and regex literals are copied verbatim. A slash starts a regex when it follows an operator, an opening bracket or a keyword such as return; otherwise it is division. Whitespace is dropped unless two word characters would merge, or two plus or minus signs would fuse into ++ or –. A line break survives only where both sides could continue a statement, which is where semicolon insertion may depend on it.

When not to use it

  • For production bundles, use a build tool that also shortens names and removes unused code.
  • Code that depends on Function.prototype.toString output or on license comments needs those comments kept.

Common mistakes

  • Minifying the only copy of a file and losing the readable source.
  • Expecting this pass to shrink files as much as Terser, which also renames local variables.

Frequently asked questions

Will the minified code behave the same as the original?

For valid scripts, yes. Only comments and whitespace between tokens are removed, and literals are untouched. Line breaks that automatic semicolon insertion could rely on are kept, so code written without semicolons still parses the same way.

Why are some line breaks still in the output?

A line like x = 1 followed by y = 2 has no semicolon, so the line break ends the statement. Joining them would produce x=1y=2, which is a syntax error. The tool keeps such breaks and shows a warning.

Does it rename variables like Terser or UglifyJS?

No. Renaming needs a full parser with scope analysis. This tool only strips comments and whitespace, which typically saves 20 to 40% on commented, indented source.

Are license comments starting with /*! preserved?

No, every comment is removed. If a license requires its notice to stay, paste it back at the top of the minified output.

How does it tell a regex from a division sign?

It looks at what came before the slash. After an operator, an opening bracket, a comma or a keyword like return, the slash starts a regular expression; after a name, number or closing bracket it is division.

Is my code uploaded anywhere?

No. The minification runs in your browser, and an opened file is read locally without being sent to a server.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 25). JavaScript Minifier. Tools Directory. Retrieved October 26, 2026, from https://tools.milunir.com/developer-tools/programming-language-tools/javascript-minifier/

MLA

Tools Directory Editorial Team. “JavaScript Minifier.” Tools Directory, 25 Oct. 2026, https://tools.milunir.com/developer-tools/programming-language-tools/javascript-minifier/. Accessed 26 Oct. 2026.

Chicago

Tools Directory Editorial Team. “JavaScript Minifier.” Tools Directory. Last modified October 25, 2026. Accessed October 26, 2026. https://tools.milunir.com/developer-tools/programming-language-tools/javascript-minifier/.

Link<a href="https://tools.milunir.com/developer-tools/programming-language-tools/javascript-minifier/">JavaScript Minifier – Tools Directory</a>