JavaScript Minifier

Minify common JavaScript source code by reducing unnecessary whitespace for compact browser delivery.

Ad space — place your AdSense unit here after approval.
Note: this is a pattern-based formatter. Check string literals, template literals and regular expressions in the output before using it in production.
Your result will appear here.

JavaScript Minifier online

Minify JavaScript by stripping comments and collapsing whitespace — for small scripts you ship by hand and snippets that live inside other documents.

Quick answer: Minify common JavaScript source code by reducing unnecessary whitespace for compact browser delivery.

How to use this tool

  1. Paste your JavaScript into the input box.
  2. Click Minify. Block and line comments are removed, whitespace collapses, and spaces around operators and punctuation are squeezed out.
  3. Copy the minified code — and test it before you ship it (see the note on strings below).

Common uses

Shrinking a hand-maintained script for a static site, embedding a snippet into an HTML page or a tag manager, fitting code into a size-limited field, and quick size checks while prototyping.

How it works

This is a textual minifier: it removes /* */ and // comments, folds all whitespace runs to single spaces, then removes the spaces around common punctuation and operators. It does not parse, so it cannot rename variables, drop dead code or fold constants the way a bundler-grade minifier (Terser, esbuild) does — the saving is the formatting layer only. That simplicity has a sharp edge: the comment and whitespace rules apply inside string and template literals too, so a string containing // after a space, or meaningful double spaces in a template, can be altered. Always run the minified output before deploying it.

Worked example

The snippet

// greeting
function greet(name) {
  return "Hi " + name;
}

minifies to function greet(name){return "Hi "+name;} — comment gone, structure squeezed, the string's inner space preserved because it is not around punctuation. Note the surviving space in "Hi ": spaces are removed around operators, not inside quotes — unless a quote contains a comment look-alike, as warned above.

Privacy and browser processing

Your code is minified in your browser with JavaScript — it is never uploaded or stored.

Frequently asked questions

Why must I test the output?

Because the minifier is regex-based: a template literal holding meaningful spacing or newlines, a regex literal, or a string containing " //" can change meaning when whitespace collapses. Thirty seconds of testing beats a broken page.

Why is the file bigger than what my bundler produces?

Bundlers parse the code and can safely rename locals, drop unreachable code and inline constants. A textual squeeze keeps every identifier as-is. For production bundles, use Terser or esbuild; for a quick inline snippet, this is enough.

Does it support modern syntax?

The squeeze is syntax-agnostic — classes, arrow functions and optional chaining pass through as text. The same warning applies: modern code leans on template literals, which deserve a test run after minifying.

Can it minify a whole project?

It handles one paste at a time and is meant for snippets and single files. Project-scale work belongs in a build pipeline where source maps and automated tests exist.

Is my code uploaded?

No. Minification runs in your browser; nothing is sent anywhere.

Related tools

Ad space