JavaScript Minifier: Strip Comments and Whitespace Safely

Paste JavaScript to remove comments, indentation and unneeded spaces. Strings, template literals and regex literals are copied untouched, and a line break stays wherever removing it could change what the code does. Nothing is renamed and nothing is uploaded.

Ad Space

A JavaScript minifier is a tool that makes a script smaller without changing what it does, by removing characters the browser does not need: comments, indentation and spaces between tokens. This one runs in your browser, leaves every name and string untouched, and shows the bytes saved.

How This JavaScript Minifier Works

The tool reads your code one token at a time (a word, a number, a string, an operator) and copies each token unchanged. It only decides what goes between two tokens: nothing, a single space, or a single line break. Because strings, template literals and regex literals are whole tokens, text such as "http://a//b" or /https?:\/\// is never mistaken for a comment.

Part of the codeWhat happens
// line and /* block */ commentsRemoved
/*! ... */ commentsKept, since they usually hold a licence notice
Indentation, blank lines, spaces around operators and bracketsRemoved
Strings, template literals, regex literalsCopied character for character
A line break where a statement could end (after return, a value, ), ] or })Kept as one line break, because JavaScript may insert a semicolon there
a + +b, a - -b, 1 .toFixed()One space kept so two tokens do not merge into one
Variable, function and property namesUnchanged

Worked Example: Before and After

Press Load Example above to reproduce this. The input has no semicolons, a URL inside a string, a regex with slashes and a template literal that looks like it contains a comment.

// Greeting helper
function greet(name) {
  /* Say hello */
  var site = "https://example.com/a//b";   // not a comment
  var isUrl = /^https?:\/\//.test(site)
  console.log(`Hello,   ${name}!  // still text`, site, isUrl)
}

greet("World")

Output:

function greet(name){var site="https://example.com/a//b";var isUrl=/^https?:\/\//.test(site)
console.log(`Hello,   ${name}!  // still text`,site,isUrl)}
greet("World")

Both versions print the same line when run. The two comments and the indentation are gone, the string, regex and template are untouched, and two line breaks remain because the statements before them have no semicolon.

How Much Smaller? Measured Results

InputOriginalMinifiedSaved
Example above240 bytes167 bytes73 bytes (30.4%)
Our 110-line edge-case test file3,506 bytes2,495 bytes1,011 bytes (28.8%)
The same test file after gzip1,770 bytes1,381 bytes389 bytes (22.0%)

The saving depends on how many comments and how much indentation a file has; code that is already compact shrinks very little. In October 2026 we ran 6,202 open-source JavaScript files (47.9 MB in total) through this minifier and parsed every result: each file produced the same syntax tree as its original, and the total size fell by 38.8%. The test file was also run with Node.js before and after minifying and printed identical output.

Limits: What This Tool Does Not Do

After minifying, the tool checks that the result still parses whenever your input parses as a classic script, and shows the outcome next to the byte counts. Files that use import or export are minified the same way, but that check is skipped for them.

Why Minify JavaScript?

Chrome's Lighthouse documentation describes minification as "the process of removing whitespace and any code that is not necessary to create a smaller but perfectly valid code file", and Lighthouse has a "Minify JavaScript" audit that lists unminified files with the potential saving (Chrome for Developers). Smaller files download faster. Servers usually compress JavaScript with gzip or Brotli as well; the two stack, as the gzip row in the table shows. All processing here happens in your browser, so the code you paste is never sent to a server.

Last updated: October 2026

Frequently Asked Questions

Does this minifier rename variables or change code structure?

No. It removes comments, indentation and unneeded spaces and line breaks only. Names, strings, regex literals and the order of statements stay exactly as written, so it is not an obfuscator and it does not remove unused code.

How much space does basic JavaScript minification save?

It depends on how many comments and how much indentation the file has. In our tests a 110-line commented test file went from 3,506 to 2,495 bytes (28.8% smaller) and the short example on this page from 240 to 167 bytes (30.4%). The tool shows the exact bytes saved for your input.

Is this safe for production use?

The minifier copies strings, template literals and regex literals untouched, keeps a line break wherever removing it could change the meaning, and runs a syntax check on the result. It is still a tokenizer rather than a full parser, so run your tests on the output. For a build pipeline, a parser-based minifier is the better choice and also produces smaller files.

Is my JavaScript code sent to any server?

No. All processing happens entirely in your browser using JavaScript. Your source code never leaves your device.

What is the difference between minification and uglification?

Minification here means removing comments and whitespace. Uglification goes further by renaming variables to shorter names, removing dead code and rewriting expressions. This tool does the first only, which keeps the output readable enough to debug.

Does minifying JavaScript change how the code runs?

It should not. Comments and spacing have no effect on behaviour, with one exception: JavaScript can end a statement at a line break. This minifier therefore keeps a line break wherever a statement could end there, for example after return or between two statements written without semicolons.

Can minified JavaScript be reversed?

Partly. A formatter can restore indentation and line breaks, but removed comments cannot be recovered. Because this tool does not rename anything, the reformatted code reads the same as your original apart from the missing comments. Keep your source file and treat the minified file as a build output.