JavaScript Minifier - Compress JS Code Online

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.

Live Example

Here is a small function before and after minification. The behavior is identical — only the comments, indentation, and extra spacing are removed:

Input (formatted)

function greet(name) {
  const message = 'Hello, ' + name + '!';
  return message;
}

Output (minified)

function greet(name){const message='Hello, '+name+'!';return message;}

How to Use JavaScript Minifier

  1. Open the tool: Click Try It to launch the two-pane editor.
  2. Paste Your JavaScript: Enter or paste the script you want to compress into the input area on the left.
  3. Minify Automatically: The tool instantly strips comments, whitespace, and redundant separators while preserving your logic and strings.
  4. Review Savings: Check the original size, minified size, and percentage saved shown above the output.
  5. Copy or Download: Copy the minified JS to your clipboard or download it as a .js file for your build.

Key Features

  • Removes comments and whitespace: strips // and /* ... */ comments, line breaks, and indentation that the engine does not need.
  • Collapses redundant separators: drops the spaces around braces, operators, and commas while keeping token boundaries safe.
  • Preserves strings and regex: content inside quotes, template literals, and regular expressions is protected and never mangled.
  • Safe spacing: a space is kept where removing it would merge two tokens (for example, return x stays valid).
  • Live compression statistics: see the original size, minified size, and percentage saved in real time.
  • Copy or download: grab the minified JS to your clipboard or save it as a .js file.
  • 100% private & client-side: everything runs in your browser — nothing is uploaded or stored.

Common Use Cases

  • Production optimization: Compress scripts before deploying to reduce bandwidth and improve load times.
  • Core Web Vitals: Shrink JS weight to speed up interactivity and boost your First Contentful Paint score.
  • Inline scripts: Minify a small script before embedding it in the <head> or before a closing </body> tag.
  • Email and widget snippets: Minify tracking pixels, share buttons, and widgets to keep payloads small.
  • Code cleanup: Remove leftover comments and formatting from generated or hand-written scripts.

About JavaScript Minification

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++.

What a Minifier Removes

A typical JavaScript minifier targets three kinds of dispensable text:

  • Comments:// ... and /* ... */ blocks carry no meaning at runtime and are stripped entirely.
  • Whitespace: newlines, tabs, and multiple spaces collapse to nothing or a single significant space.
  • Redundant separators: spaces around braces, operators, and commas are dropped wherever it is safe to do so.

How It Stays Safe

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.

Minify vs Beautify vs Gzip

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.

Common JavaScript Minification Issues & How to Fix Them

  • Adjacent keywords or identifiers: a naive minifier can turn return x into returnx. This tool keeps the space whenever two word-characters would touch, so such cases stay valid.
  • Plus signs collapsing: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.
  • Comments removed: minification strips // and /* */ comments. If you need a license header to survive, keep an un-minified source copy and re-add it after minifying.
  • Regex vs division: a slash is ambiguous. The tokenizer decides regex-vs-division from context; if an unusual expression confuses it, add parentheses around the regex in your source.
  • No size savings: if the JS was already minified, there is little left to remove. Feed it formatted source to see real savings.

Related Tools

Pair this minifier with its counterpart and the rest of our formatting and compression utilities:

Frequently Asked Questions

1What does a JavaScript minifier do?

A JavaScript minifier removes comments, whitespace, line breaks, and redundant separators from your script to reduce its file size while keeping the behavior identical.

2How much can I reduce my JavaScript file size?

Reduction depends on how much formatting and how many comments your code has, but typically you can save 20-60% of the original size. Already-minified code shows little further savings.

3Does minification change how my code runs?

No. Minification only removes characters the engine ignores, so your program behaves exactly the same — the file is just smaller and faster to download and parse.

4Is my JavaScript uploaded to a server?

No. Minification runs entirely in your browser, so your code never leaves your device and stays completely private.

5Will minification break strings or regular expressions?

No. The tool protects quoted strings, template literals, and regular expressions, and it keeps a space where removing it would merge two tokens, so 'return x' stays valid.

6What is the difference between minify and gzip?

Minification shrinks the JavaScript source text, while gzip or Brotli compresses the bytes on the wire. The two stack — minify first, then let your server compress for the smallest transfer size.

7Does this tool rename variables like a bundler minifier?

No. It strips whitespace and comments but keeps your identifiers intact. For the deepest compression (mangling, dead-code removal), feed its output through a build minifier like Terser or SWC.

8Can I download the minified JavaScript?

Yes. After minifying, you can copy the result to your clipboard or download it as a .js file for use in your build.

9Why does a space sometimes remain between two operators?

A space is kept whenever removing it would change tokenization, such as 'a + +b' collapsing into 'a+++b'. This keeps the minified code valid and equivalent to the original.

10Does it work on mobile?

Yes, the JavaScript Minifier is fully responsive and runs in any modern browser on desktop, tablet, and mobile.