Skip to content

JavaScript Minifier for Comments and Whitespace

Remove comments, indentation and blank lines from a script and see the before and after size. Variable names are left exactly as you wrote them.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Minified JavaScript

function greet(name){return `Hello,${name}!`;}

Savings

Before
70 chars
After
46 chars
Saved
34%

Good to know. This is a lightweight whitespace and comment minifier. For production builds use a real bundler such as esbuild, SWC or Terser, which also rename variables and remove dead code.

Quick answers

What does minifying JavaScript do?
It removes characters the JavaScript engine does not need, such as comments, indentation and line breaks, so the file is smaller to download. Full minifiers also shorten local variable names and delete unreachable code. The program's behaviour is meant to stay identical.
Does this minifier rename variables?
No. It removes comments and whitespace only. Function names, variable names and the structure of your code are unchanged, which keeps the output easy to debug but larger than the output of Terser, esbuild or SWC.
How much smaller will my JavaScript get?
It depends on how heavily the source is commented and indented. The worked examples on this page save between 28% and 40%. Code with long documentation comments saves more; code already written compactly saves only a few percent.
How do I remove comments from JavaScript?
Paste the code and copy the output. Both /* block */ comments, including multi-line and JSDoc blocks, and // line comments are removed. A // that directly follows a colon, quote, backtick or backslash is kept, so URLs such as https://example.com survive.
Can minifying break my code?
With this tool, yes, in specific cases: a string containing // is cut short unless a colon, quote, backtick or backslash comes directly before it, spaces around commas, semicolons and braces inside strings are removed, and a line ending in } with no semicolon is joined to the next statement. A parser-based minifier avoids all three.

About JavaScript Minifier

This is a light, text-based minifier. It deletes /* block */ and // line comments, trims every line, drops blank lines, and removes the spaces and line breaks around braces, semicolons and commas. In the worked examples below that removes 28% to 40% of the characters. It does not parse the code, so it never renames variables, removes unused functions or shortens expressions, and the output stays readable. The same simplicity means it applies its rules inside string literals too: a string containing a comma followed by a space, or a brace or // with spaces around it, will be changed. Read the limits below and test the result before you ship it.

JavaScript minify examples with real output

Each result is the tool's exact output for the input described, with the figures from the Savings panel.

A function with a line comment

function add(a, b) { // sum two numbers / return a + b; } then const result = add(2, 3); and console.log(result); written over 7 lines

function add(a,b){return a + b;}const result = add(2,3);console.log(result); Before 107 chars, After 76 chars, Saved 29%.

A loop with a block comment and trailing comment

var total = 0; /* running sum */ then for (var i = 1; i <= 10; i++) { containing total += i; // add indented 4 spaces, a closing brace, then console.log(total); written over 5 lines

var total = 0;for (var i = 1;i <= 10;i++){total += i;}console.log(total); Before 109 chars, After 73 chars, Saved 33%.

An exported arrow function with a JSDoc block

A 4-line /** Format a price. @param {number} n */ block above export const price = (n) => { ... } with two return statements

export const price = (n) =>{if (n === 0) return "free";return "$" + n.toFixed(2);}; Before 139 chars, After 83 chars, Saved 40%.

Code written without semicolons

const x = 10 // ten, const y = 20 // twenty, console.log(x + y) on three lines

The three statements stay on three separate lines with the comments gone. Before 61 chars, After 44 chars, Saved 28%.

Line breaks are kept unless they sit next to a brace, semicolon or comma, so statements that rely on a line break to end them are not glued together.

What gets removed and what stays

In your codeWhat happensExample
/* block comments */Removed, including multi-line and JSDoc blocks/** docs */ disappears
/*! licence banners */Removed like any other block comment/*! license MIT */ var a = 1; becomes var a = 1;
// line commentsRemoved to the end of the linex = 1; // note becomes x = 1;
// after a colon or quoteKept"https://example.com" and "//cdn.example.com/app.js" are unchanged
Indentation and trailing spacesRemoved from every line4-space indents vanish
Blank linesRemovedGaps between functions close up
Space or line break around { } ; ,Removedadd(a, b) { becomes add(a,b){
Spaces around operatorsKepta + b and x === 3 are unchanged
Line breaks between statements with no ; or }Keptconst a = 1 stays on its own line
Variable and function namesKeptresult stays result

Three inputs this minifier gets wrong

These are real outputs. If your code contains one of these patterns, fix it by hand afterwards or use a parser-based tool.

Punctuation with spaces inside a string

const msg = "Hello, world; bye";

const msg = "Hello,world;bye";

The spaces after the comma and semicolon are removed even though they are inside quotes, so the text shown to users changes. The sample greet function is affected the same way: its template string loses the space after the comma, so the greeting reads Hello,Ada! instead of Hello, Ada!

Two slashes after a space inside a string

const note = "a // b";

const note = "a

Everything from // to the end of the line is treated as a comment, leaving an unterminated string and a syntax error. The same happens after any character other than a colon, quote, backtick or backslash, so "a//b" is cut as well.

An object literal with no semicolon after it

const o = { a: 1 } on one line and const p = 2 on the next

const o ={a: 1}const p = 2

The line break after the closing brace is removed, which joins two statements into invalid code. Ending such lines with a semicolon avoids it.

Whitespace minifier vs Terser, esbuild and SWC

Parser-based minifiers read the code into a syntax tree before rewriting it, which is what lets them make deeper changes safely.

CapabilityThis toolParser-based minifier
Remove comments and indentationYesYes
Leave string and regex contents untouchedNot alwaysYes
Remove spaces around operatorsNoYes
Shorten local variable names (mangling)NoYes
Remove unreachable and unused codeNoYes
Keep licence comments on requestNoYes
Produce a source mapNoYes
Needs installing or a build stepNoUsually

When a quick comment and whitespace pass is the right tool

  • Stripping developer comments, ticket numbers and TODO notes from a small script before it goes on a public page.
  • Fitting a snippet into a field with a character limit, such as a tag manager, a CMS script box or a bookmarklet.
  • Shrinking an inline script on a static page that has no build pipeline.
  • Seeing how much of a file is comments and layout: the Saved percentage is a close guide to that share.
  • For application bundles, use the minifier built into your bundler instead. It will save more and will not touch your strings.

How to get your result

  1. 1

    Paste your code into the JavaScript box, replacing the sample greet function.

  2. 2

    Read the Minified JavaScript panel. There are no options to set.

  3. 3

    Check the Savings panel for the Before and After character counts and the percentage Saved.

  4. 4

    Compare any string literals in the output with the original, then run the minified code once to confirm it behaves the same.

  5. 5

    Copy the result, or download it as script.min.js.

Frequently asked questions

Is my code sent to a server?
No. The minification is a handful of text replacements run by your browser. The code you paste stays on your machine, so proprietary scripts are not transmitted or stored.
Is minifying still useful if my server uses gzip or brotli?
Yes, though the gain is smaller than the raw figure. Compression shrinks repeated whitespace well, but it cannot delete comments, and the browser still has to parse every character after decompressing. The two are normally used together.
Does it work with ES6+, JSX or TypeScript?
It does not parse syntax, so modern JavaScript such as arrow functions, classes, modules and template literals passes through. JSX and TypeScript are also treated as plain text, but the result is still JSX or TypeScript and must be compiled before a browser can run it.
Will it keep my licence comment?
No. Every block comment is removed, including ones that start with /*! which other minifiers preserve by convention. If a library's licence requires the notice, paste it back at the top of the minified file.
Why is there still whitespace in the output?
Only whitespace next to a brace, semicolon or comma is removed. Spaces around operators, after keywords and inside parentheses are kept, as are line breaks between statements that have no semicolon. A full minifier removes those as well.
Can I undo minification later?
Line breaks and indentation can be restored with a code formatter, but deleted comments are gone for good. Keep the original source file under version control and treat the minified file as a generated copy.
Should I use this for a production build?
For a small standalone snippet that you have tested, it is fine. For an application, use Terser, esbuild or SWC through your bundler: they understand the syntax, protect strings and regular expressions, rename local variables and usually produce a much smaller file.

Looking for something else? Browse all developer tools or see every tool.