Skip to content

JavaScript Minifier

Remove comments and whitespace without breaking your code.

Quick Tool Overview

The JavaScript Minifier removes comments and the whitespace that provably cannot change meaning, tokenising strings, template literals and regular expressions properly rather than pattern-matching them. It will not collapse the file onto one line, because a line break in JavaScript can be doing a semicolon's job and no amount of whitespace cleverness knows which ones are.

What it does
Removes JS comments and safe whitespace
You give it
JavaScript, as a file or a fragment
You get back
Smaller JavaScript that still parses and behaves identically
Best for
A quick, reviewable reduction without a build step
SEO Tools Free, unlimited use No sign-up Runs in your browser

About the JavaScript Minifier

Paste JavaScript and the minifier removes comments and the whitespace that provably cannot change meaning. Strings, template literals and regular expressions are tokenised properly rather than pattern-matched, so nothing inside them is touched.

It will not collapse your file onto one line, and that is deliberate. JavaScript inserts semicolons at line breaks under rules that depend on what is on either side, so `a` newline `(b)` and `a(b)` are two different programs. This minifier only removes a line break after a character that cannot end a statement, which makes the transformation safe by construction rather than safe in testing. What it does not do is rename variables, remove dead code or restructure anything — a real compressor like Terser does all three and will beat this comfortably. This is for the case where you want a smaller file you can still read the diff of.

Key features of the JavaScript Minifier

Real tokenising

Strings, templates with nested interpolation and regex literals are recognised, not guessed at.

Regex versus division

A slash is read in context, so a regular expression is never mistaken for a division sign.

Semicolon insertion respected

A line break is only removed after a character that cannot end a statement.

Operator spacing kept

a + +b never becomes a ++b, which is the classic whitespace-minifier bug.

Honest about its ceiling

It says plainly that Terser will beat it, and what Terser does that this does not.

How to use the JavaScript Minifier

  1. 1

    Paste your JavaScript

    A file or a fragment. It stays in your browser.

  2. 2

    Check the saving

    Before and after sizes with the percentage and a gzipped estimate.

  3. 3

    Read the output

    Line breaks that were doing a semicolon's job are kept, so the result is still readable.

  4. 4

    Copy or download

    Take the result into your page or your build step.

Frequently asked questions

It is built not to. Strings, templates and regular expressions are tokenised rather than pattern-matched, and a line break is only removed after a character that cannot end a statement — which is exactly the rule automatic semicolon insertion turns on. That said, always test the output before shipping it.

Reviews of the JavaScript Minifier

What people who use the JavaScript Minifier think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the JavaScript Minifier. It takes half a minute and no account.

Write the first review

More SEO tools