JavaScript Minifier

Minify JavaScript — strip comments and collapse whitespace to shrink a script — right in your browser. A naive regex minifier: fast, but it can break real code.

Developer Tools Free No upload Instant

Loading JavaScript Minifier…

Your browser is preparing the tool. It runs 100% locally.

Quick Answer

Paste JavaScript and the tool removes comments and the whitespace around operators and punctuation, collapsing the script toward one line. Be warned: it is a naive regex minifier, not a real one. It does not understand strings, template literals or regular expressions, so it can break working code in those cases. Use it for trivial snippets and reach for a proper minifier like Terser for anything real. It runs in your browser; nothing is uploaded.

What the JavaScript Minifier Does

This tool makes a quick attempt at shrinking JavaScript by deleting comments and squeezing out the whitespace that the engine does not need — the indentation, and the spaces around operators and punctuation. For simple, self-contained snippets the output is smaller code that still runs.

It is a fast, no-build way to compress a small script. But because it works by pattern-matching rather than understanding the language, it comes with real caveats — it is best thought of as a rough whitespace squeezer, not a production minifier.

How It Works

The tool runs a sequence of regular expressions: it removes block comments and line comments, strips the indentation at the start of each line, removes the whitespace on either side of operators and punctuation, and finally joins the lines together. There is a small guard so that the slashes in a URL like a https address are not mistaken for a comment.

Crucially, it never parses the code. It does not know where a string starts or ends, what is inside a template literal, or where a regular expression sits. It just reacts to characters. That is why it is fast and dependency-free — and also why it can corrupt code that a real, parser-based minifier would handle safely.

Processing pipeline

  1. Remove comments. Delete block comments and line comments, with a guard so a URL is not treated as a comment.
  2. Collapse indentation. Strip the leading whitespace from each line.
  3. Trim around operators. Remove whitespace on both sides of operators and punctuation.
  4. Join the lines. Merge the lines into a compact result and trim it.

What it does (and where it fails)

• remove block and line comments (with a guard for a URL) • strip leading indentation • remove whitespace around operators and punctuation • join the lines into one it never parses — it cannot see strings, templates or regex
Worked example
Before: function add(a, b) { return a + b; } After: function add(a,b){return a+b;}

That simple case works. But a line comment marker inside a string gets treated as a comment and truncates the string; a multi-line template literal has its indentation collapsed, changing the text; and removing spaces around the divide sign can corrupt a regular expression. A parser-based minifier avoids all of these.

Privacy

Your code never leaves your device. It is minified in your browser with no network request, so nothing is uploaded.

Because the work is local, you can run it on proprietary scripts without them being stored or sent anywhere — though for real code you should use a proper minifier.

Nothing persists between sessions — close the tab and the input and output are gone.

Standards & references

  • Minification — Removing characters that are not needed to run the code — whitespace, comments — to reduce file size. Done safely, it does not change behaviour; done naively, it can.
  • AST-based minifiers — Tools like Terser and esbuild tokenise and parse the code into a syntax tree, leave strings, template literals and regex untouched, and can even rename variables. That safety is impossible with regular expressions alone.
  • Automatic semicolon insertion — JavaScript can infer some semicolons from line breaks. Joining lines by removing newlines can change behaviour where a semicolon was implied — another reason a parser is needed for safe minification.

Accuracy & Limitations

For a small, self-contained function the output is correct and smaller. But this is a naive regex minifier, and on real code it can break things — it is best used only for trivial snippets you can eyeball afterwards.

It does not understand strings. A line-comment marker inside a string is treated as the start of a comment, so the rest of that line — including the closing quote — is deleted, corrupting the code. A parser knows the marker is inside a string and leaves it alone.

Template literals and regular expressions are at risk too. The indentation inside a multi-line template literal is collapsed, changing the text it produces, and removing the spaces around the divide sign can mangle a regular expression. The tool cannot tell these apart from ordinary code.

It does not rename variables or do any real optimisation, so even when it works it compresses less than a proper minifier. And by joining lines it can run into automatic-semicolon-insertion issues. For anything beyond a trivial snippet, use Terser or esbuild.

Real-World Use Cases

Squeezing a tiny snippet

Compress a few lines of simple JavaScript you can check by eye.

A quick size estimate

See roughly how much whitespace a small script carries.

Learning what minifying does

Watch comments and spacing disappear from simple code.

Inlining a trivial function

Shrink a small, string-free function for a quick paste.

When to use it — and when not to

Good for

  • Compressing a trivial, string-free snippet
  • A rough idea of the whitespace saving
  • Learning what minification removes
  • Quick eyeball-and-check experiments

Not the best choice for

  • Any production or shared code
  • Scripts with strings, templates or regex
  • Code that relies on automatic semicolons
  • Maximum or safe compression

For anything real, use a parser-based minifier — Terser or esbuild — which preserves strings, template literals and regex, handles semicolons safely, and can rename variables for far better compression. This tool is only for trivial snippets you will verify by hand.

Frequently Asked Questions

Can this break my JavaScript?
Yes. It is a naive regex minifier that does not parse the code, so it can corrupt strings that contain a comment marker, collapse multi-line template literals, and mangle regular expressions. Use it only for trivial snippets and check the result.
Why would it delete part of my string?
If a string contains the line-comment marker, the tool treats it as the start of a comment and removes the rest of the line, including the closing quote. It cannot tell the marker is inside a string, because it does not parse.
Does it work on a URL in a string?
There is a small guard so the slashes in an address like a https URL are not treated as a comment, so that common case survives. Other comment-like sequences inside strings are not protected.
What happens to template literals?
A multi-line template literal has its indentation stripped, which changes the text it produces. The tool does not know it is inside a template, so the whitespace there is removed like any other.
Does it rename variables like a real minifier?
No. It only removes whitespace and comments. It does not rename variables or do any structural optimisation, so it compresses far less than Terser or esbuild, which can mangle names safely.
Is it safe for production code?
No. For production, use a parser-based minifier such as Terser or esbuild. This tool is a rough whitespace squeezer suitable only for trivial snippets you can verify by hand.
Why did my regular expression stop working?
Removing the spaces around the divide sign can run a regular expression into the surrounding code or change how it is read. The tool cannot tell a regex from division, so it treats both the same.
What is automatic semicolon insertion and why does it matter?
JavaScript infers some semicolons from line breaks. By joining lines, the tool can remove a break where a semicolon was implied, changing behaviour. A parser-based minifier inserts the needed semicolons safely.
How much smaller will my script be?
For simple code, roughly the size of its whitespace and comments. It does not rename anything, so the saving is modest compared with a real minifier that also mangles names.
Is my code uploaded anywhere?
No. It runs entirely in your browser. Nothing is sent to a server — although for real code you should use a proper minifier regardless.
Can I reverse the minified output?
You can re-indent it with a formatter to make it readable, but comments are gone and any corruption from the minify is not recoverable. Keep your original source.
Then what is it good for?
Quickly squeezing a trivial, string-free snippet, or seeing what minification does. For anything you will ship, use Terser or esbuild instead.

References

Shrinks by stripping comments and removing whitespace around operators with regular expressions; honest that this naive approach can corrupt strings, template literals and regex patterns, so it is for trivial snippets only.

PopularHot

JSON Formatter

JSON Formatter for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

JSON Validator

JSON Validator for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Base64 Encoder

Base64 Encoder for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Hash Generator

Fast, free Hash Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Popular

UUID Generator

Fast, free UUID Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Trending

CSS Minifier

Fast, free CSS Minifier that runs entirely client-side in your browser.

DeveloperOpen Tool

Ready to try the JavaScript Minifier?

It is free, private and runs entirely in your browser — no sign-up, no uploads, no limits.