How to Compress JavaScript
Every comment and indent in a script is a byte your visitors download. This page strips them out so the file you deploy is smaller, without touching what the code does. If you only want to tidy the code up instead, the JavaScript Beautifier goes the other way.
Add your JavaScript
Any plain JavaScript works, including ES modules and React JSX:
Example: JavaScript before compression
// Double every number in the list
function processData(data) {
const result = [];
for (let i = 0; i < data.length; i++) {
result.push(data[i] * 2);
}
return result;
}Let it compress
Compression starts on its own about a third of a second after you stop typing. Here is what happens:
Example: the same code, compressed
function processData(data){const result=[];for(let i=0;i<data.length;i++){result.push(data[i]*2);}return result;}180 bytes down to 113. Short snippets like this shrink less than a large, well-commented file.
Check the size and save it
Frequently Asked Questions
What does the compressor actually remove?
Comments, indentation, blank lines and the spaces between tokens that JavaScript doesn't need. Your code is read with Babel's parser and printed back on as few characters as it safely can, so return followed by a value on the next line, a - -b and code written without semicolons all keep their meaning. Comments that start with /*! or contain @license or @preserve are kept, because licences usually require them.
Will it change my strings, numbers or regular expressions?
No. Anything inside quotes, template literals or a regex is copied character for character, so a URL like https://example.com//path or a string with two spaces stays as it is. Numbers keep their spelling too: 8901240544102066246, 0x1F, 14.50 and a quoted "00501" come out exactly as you typed them. Variable and function names are never shortened either.
How much smaller will my file get?
It depends entirely on how the code was written. Heavily commented, well-indented source shrinks a lot; code that is already tight barely moves, and a one-liner can even come out a byte or two longer when a missing semicolon gets added. The bar above the result shows the real UTF-8 size before and after, so you don't have to guess.
Do I still need gzip or Brotli on my server?
Yes, the two work together. This page removes characters from the source; gzip or Brotli on your server then compresses whatever bytes are left while they travel over the network. Stripping comments and whitespace first usually makes the compressed transfer smaller as well, but the saving on the wire is smaller than the number shown here.
Why does it show an error instead of compressing my code?
The code has to parse before anything is removed, so a syntax error stops the run and you see the line and column with a caret under the spot. If you pasted JSON, CSS or TypeScript by mistake, the message says so. TypeScript needs to be compiled to JavaScript first, or you can use the TSX Minifier for it.
Is my code uploaded anywhere?
No. The compression happens in your browser and the code isn't sent to our server or kept. A reload starts with an empty editor.
Related tools: the JavaScript Minifier, the TSX Minifier for TypeScript and the CSS Minifier.