This page removes comments, indentation, blank lines and repeated spaces from JavaScript. It does not rename variables, join lines, fold constants or drop dead code. The result is shorter and still readable, which is a different goal from a production bundle minifier.
The caution is deliberate. Automatic semicolon insertion means a line break can be part of the program's meaning, so joining lines is one of the riskiest transformations a minifier can make. This page leaves line breaks alone and states that in its note. Use it to reduce a snippet, an inline script or a file you are about to review, not to replace a build step.
What the three options remove
Remove comments deletes both line comments and block comments. A licence header or a build instruction inside a comment is lost, so keep the original. The stats report how many comments were found, which is a useful check before you decide the output is safe.
Remove indentation and trailing spaces strips leading whitespace from every line and any spaces at the end. Lines start at the first character, so an indented function body loses its shape.
Remove blank lines deletes empty lines and lines containing only whitespace. Because line breaks between code lines are preserved, the output still has one statement per line where the input did.
Repeated spaces inside a line
A run of spaces or tabs between two tokens is now collapsed to a single space, and that space is dropped next to punctuation. const total = items.reduce(…) becomes const total = items.reduce(…), and const b = [ 1 , 2 , 3 ] ; becomes const b = [1,2,3];.
The rule is positional rather than semantic. A space is removed when the character before it is an opening bracket, brace, comma, semicolon, colon or dot, or when the character after it is a closing bracket, brace, comma, semicolon or colon. Everywhere else a single space stays, which is why return -1 and typeof x keep their separator.
A space before a dot is kept, because (1) .toString() and 1 .toString() need it: deleting the one after a number turns the call into a syntax error. Spaces inside strings, template literals, regular expressions and comments are never touched, so "a b" and a template containing three spaces come back exactly as written.
Removing an inline block comment no longer leaves two spaces behind. If /* note */ sat between two identifiers with no other separator, one space is inserted so the tokens do not merge, and the run of whitespace around it is collapsed to one.
Line breaks and automatic semicolon insertion
JavaScript inserts a semicolon at a line break in some situations, and the rule depends on what comes next. A minifier that joins lines without understanding the grammar can turn two statements into one expression or change a return followed by a newline into a function that returns nothing. This page avoids the whole class of problem by never joining lines.
The cost is that the output is not as small as it could be. A real minifier parses the program, joins lines safely, renames local variables to short names and removes unreachable code. It can cut a file by 60% or more. This page typically saves 15-35% on commented, indented source, and much less on code that is already compact.
If you need the aggressive behaviour, use a parser-based tool and run your tests afterwards. Do not paste the output of this page into production expecting bundle-size results.
A worked example
A 273-character function with a line comment, a block comment, indentation, repeated spaces and a blank line was minified with comments and indentation removed. The result was 174 characters, 36.3% smaller, with two comments removed.
| Input | Options | Result |
|---|---|---|
| 273-character function | Comments and indentation | 174 characters, 36.3% smaller |
| Same function | Comments, indentation, blank lines | 173 characters, 36.6% smaller |
| Same function | Indentation only, comments kept | 260 characters, 4.8% smaller |
| 44,575-character script file | All three options | 37,738 characters, 15.3% smaller, still parses |
The all-options output kept every statement and every token. The comment above the function and the block comment before the if were gone, the indentation was removed, and the blank line between the function and the conditional disappeared. The code still has one statement per line and the same braces.
The run with comments kept is a useful comparison: it saved only 4.8%, because the input was already free of most extra whitespace. The large file is the more realistic figure for hand-written code with comments throughout, and its output was compiled by the browser to confirm that it still parses.
if (items.length) keeps the space before its bracket. Removing it is usually harmless, but the same edit on async (x) => {} would turn an async arrow into a call, so the tool stays conservative.Comments, strings and regular expressions
Comment markers inside a string are not comments. A URL such as "https://example.com/a//b" contains // and a regular expression such as /https?:\/\/\//g contains escaped slashes. Both are copied intact, and only a real comment is removed.
Template literals are treated as strings, so a // or /* inside one is not removed either. A regex literal immediately after a division operator is the classic ambiguous case. This tokeniser also recognises return, typeof, case, in, of, new, delete, void, throw, else, do, yield and await as positions where a slash starts a regex, so return /a'b/.test(s) no longer lets the apostrophe open a string.
The tool does not shorten strings, change quote style or escape characters. Whatever was inside the quotes stays byte for byte. That makes the output safe to compare with the original once comments and whitespace are ignored.
What a build minifier does differently
A build minifier parses the file into a syntax tree, renames local bindings, removes unused code, folds constants and joins lines. It also produces a source map so a stack trace can point back to the original. This page produces none of that, and its output has no source map.
For a small inline script on a page, that difference rarely matters. For an application bundle, it does. Use the JavaScript beautifier to go back the other way when you need to read the code, and the code diff checker to confirm that only comments and whitespace changed.