Minify your JavaScript instantly with our free JavaScript Minifier. This tool removes comments, whitespace, line breaks, and unnecessary separators from your scripts to shrink their size and speed up page loads. It is ideal for optimizing websites, SPAs, and Node.js packages for production. Simply paste your JS and get the minified version in seconds, with live before-and-after size statistics.
Minification (also called JS compression) strips characters the JavaScript engine ignores anyway, so the program behaves identically while the file downloads and parses faster. It is different from gzip or Brotli compression, which your web server applies on top — and the two stack for the smallest transfer size. To make minified JS readable again, use the JavaScript Beautifier.
Everything runs in real time and entirely in your browser — there is no signup, no upload, and your scripts never leave your device. Paste your source and watch the minified output update as you type, with the bytes saved shown live.
Here is a small function before and after minification. The behavior is identical — only the comments, indentation, and extra spacing are removed:
function greet(name) {
const message = 'Hello, ' + name + '!';
return message;
}function greet(name){const message='Hello, '+name+'!';return message;}.js file for your build. // and /* ... */ comments, line breaks, and indentation that the engine does not need.return x stays valid)..js file.<head> or before a closing </body> tag. JavaScript minification removes characters a JavaScript engine does not need to interpret a script: comments, runs of whitespace, indentation, and the optional spaces around punctuation and operators. Because the engine ignores these, the program runs identically — but the file is smaller, so it transfers over the network faster and parses more quickly. That is why production builds of almost every framework (Webpack, Vite, esbuild, Rollup) run a minifier like Terser or SWC automatically as part of the bundling step.
Minification is not the same as gzip or Brotli compression. Minification shrinks the source text; the server then compresses the minified result further over the wire. Applying both gives the smallest payload. A safe minifier never removes characters that are significant: it preserves the content of quoted strings and template literals, and it keeps a single space where removing it would merge two separate tokens — for example return x must keep its space or it becomes the identifier returnx, and a + +b must keep a space or the pluses collapse into a++.
A typical JavaScript minifier targets three kinds of dispensable text:
// ... and /* ... */ blocks carry no meaning at runtime and are stripped entirely. A token-based minifier splits the source into strings, regex, comments, numbers, identifiers, and operators, then rejoins them without spaces — except where two adjacent tokens would merge into a different token. That is why return x, a + +b, and a / /regex/ all survive minification intact. Note that this tool does not rename variables or remove dead code the way a full bundler minifier does; for the deepest compression, feed its output through your build pipeline.
Minification and beautification are opposites: the JavaScript Beautifier re-adds indentation to minified JS so a human can read it, while the minifier does the reverse for performance. Neither is the same as gzip, which compresses bytes on the wire and is undone by the browser. For the markup side of a page you can apply the same idea with the HTML Minifier, for stylesheets use the CSS Minifier, and for data payloads use the JSON Minifier. Stack minification with server-side compression for the smallest possible transfer size.
return x into returnx. This tool keeps the space whenever two word-characters would touch, so such cases stay valid. a + +b or a++ +b can be misread as a+++b. The minifier inserts a space whenever two operators would merge, preserving the original meaning. // and /* */ comments. If you need a license header to survive, keep an un-minified source copy and re-add it after minifying. Pair this minifier with its counterpart and the rest of our formatting and compression utilities: