JavaScript Minifier

Strip comments and whitespace from JavaScript, safely.

Code Formatters Free, no sign-up Runs in your browser

JavaScript Minifier tool

Options

About the JavaScript Minifier

JavaScript Minifier removes comments and unnecessary whitespace, which is the part of minification that is always safe. Strings, template literals and regular expressions are detected and passed through untouched, because a brace or a slash inside one looks exactly like code and a minifier that cannot tell the difference corrupts the file.

What this tool deliberately does not do is rename variables. Serious minifiers shrink files much further by turning descriptive names into single letters, and doing that correctly requires parsing the whole program and understanding every scope. Doing it almost correctly breaks code in ways that only show up in production, which is the worst possible place to find out.

So the expected saving here is modest: usually twenty to forty percent on commented source, and considerably less once gzip is applied. For a production build, use a proper minifier in your pipeline. For shrinking a snippet you are about to inline in a page, this does the job without risk.

How to use the JavaScript Minifier

  1. Paste your JavaScriptSource with comments and formatting.
  2. Choose what to removeComments, blank lines and indentation.
  3. Press MinifyThe compact code appears with the size comparison.
  4. Copy or downloadTake the minified file.

Features

  • Removes line and block comments
  • Collapses whitespace and indentation
  • Strings, template literals and regex preserved exactly
  • Keeps semicolons, so automatic insertion is never relied on
  • Option to keep licence comments
  • Never renames variables, so nothing can break
  • Shows original size, minified size and percentage saved

Who uses this tool

The javascript minifier is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Shrinking a small script before inlining it
  • Removing comments from a snippet you are sharing
  • Reducing the size of an inline analytics or widget script
  • Measuring how much of a file is comments
  • Compressing a script for an environment with no build step

Frequently asked questions

Why does it not rename variables?

Because doing that safely requires fully parsing the program and resolving every scope, and getting it slightly wrong produces code that fails at runtime rather than refusing to build. A tool that cannot guarantee correctness should not take that risk with your code.

How much smaller will my file get?

Usually twenty to forty percent on commented source, and less after gzip. A full minifier with renaming and dead code removal typically does two to three times better.

Is the output safe to ship?

The transformations are byte-level and preserve semantics, so yes for the kind of script this is meant for. For a large application, a dedicated minifier in your build pipeline remains the right tool.

Are licence comments preserved?

Optionally. Block comments beginning with an exclamation mark are kept when that option is on, which is the convention for licence headers you are required to retain.

Does it handle modern syntax?

Yes. Template literals, arrow functions, classes, optional chaining and the rest are all handled, because the tool works at the token level rather than needing to understand each construct.

Is my code uploaded?

No. Minification runs entirely in your browser.

If the javascript minifier is not quite what you need, these other free tools solve closely related problems.

JavaScript Formatter

Format JavaScript with consistent indentation, spacing and statement breaks.

Code Formatters Use tool

CSS Minifier

Minify CSS by removing comments, whitespace and redundant characters.

Code Formatters Use tool

HTML Minifier

Shrink HTML by removing comments and collapsing whitespace, safely.

Code Formatters Use tool

JSON Minifier

Strip whitespace from JSON and compare original and minified sizes.

Developer Tools Use tool

Live HTML Editor

A three-pane editor with a live preview that updates as you type.

Developer Tools Use tool