JavaScript Minifier
Paste JavaScript and get it back with the comments and spaces removed. Nothing is renamed or rewritten, so it does exactly what it did. It runs in your browser and nothing is uploaded.
Test the minified file before you ship it. This page reads code with a scanner, not a full parser. It has been checked against a real JavaScript parser on thousands of programs, but JSX and TypeScript are not supported.
What it removes, and what it leaves alone
It removes comments, and the spaces and line breaks between tokens.
It does not rename variables, shorten property names, delete code it
thinks is unused or rewrite anything: what comes back is your program
with the same words in the same order. That is the whole trade. A
tool that renames things saves more, but it can break code that
reads its own names — anything using eval,
fn.name or a property another script looks up by
string — and you cannot see it happen.
Why some line breaks stay
JavaScript ends a statement at a line break when the next line could
not carry it on, so a line break is sometimes part of the meaning.
return followed by a new line returns nothing; join the
two lines and it returns the value. A line that begins with
++ is a new statement; joined up, it belongs to the
one before. And else on its own line after a statement
with no semicolon is valid only because of the break.
So a line break is removed only where it provably changes nothing, and kept everywhere else. A kept break costs one character. One removed wrongly changes what the program does.
The one thing a scanner cannot always know
A slash can begin a regular expression or be a division, and only a full parser is certain which. This page decides from the token before it, and leans towards a regular expression. That is the safe side: text inside a regular expression is copied exactly as written, so a division mistaken for one is harmless, while a regular expression mistaken for a division would lose the spaces inside it. If a supposed regular expression does not close on its line, it is given back as a division.
Check the gzipped numbers before you celebrate
Scripts are normally served compressed, and compression is very good at repeated spaces and repeated names. So this page gzips both versions and shows both. A forty per cent raw saving is often fifteen to twenty per cent of what a visitor actually downloads. Still free, still worth taking; just not what the big number suggests.
Frequently asked questions
Does it rename my variables or functions?
No. Every name is left exactly as you wrote it. Renaming is what makes a minifier risky, because it can break code that looks its own names up, and this page does not do it. The saving is smaller and the result does exactly what the original did.
Why are some line breaks still in the output?
Because in JavaScript a line break can be part of the meaning. A new line after return, before ++ or before else, and between two statements written without semicolons, all change the program if they are joined up. A break is removed only where that provably makes no difference.
Will it break my code?
It only removes comments and whitespace, and it keeps the line breaks that matter. It has been checked against a real JavaScript parser on thousands of programs, including this site's own scripts, and the result had exactly the same structure every time. Still, run your tests on the minified file before you ship it.
Does it work with JSX, TypeScript or modules?
Modules, yes: import and export are just words to it. JSX and TypeScript, no. In JSX the spaces between tags are content, so they cannot be treated as removable, and TypeScript adds syntax this page does not read.
What is a /*! comment?
The usual convention for a comment that must survive minifying, most often a licence notice. A comment containing @license or @preserve is kept too. Only a notice that already stands on its own line is kept, so it never changes where a statement ends.
Why did I get an error instead of output?
The page found a string, a template literal or a comment that never closes, and it names the line. It refuses rather than guess, because a guess could silently change your code.
Is my text sent anywhere?
No. Everything happens in JavaScript inside your own browser. Nothing is uploaded and nothing is saved - close the tab and it is gone.