JavaScript Minifier Online — Compress JS & Reduce Size

Strip comments, whitespace, and blank lines from JavaScript. Preserves string, template, and regex literals. Optional toggles for 'use strict' and license comments. 100% in your browser.

info

Heads-up. This is a heuristic state-machine minifier — it strips comments and whitespace safely for the vast majority of JavaScript, including modern ES2020+ syntax with template literals, optional chaining, and async/await. For production builds you should still use a tool with full AST parsing such as terser or esbuild — they additionally rename variables, eliminate dead code, and inline constants. This tool is for quick one-off minification, not a replacement for your build pipeline.

What is a JavaScript Minifier?

A JavaScript minifier compresses JS source by removing every byte the engine does not need to execute the program — line and block comments, indentation, blank lines, and the optional whitespace around punctuation like {}, (), commas, semicolons, and operators. String literals, template literals, and regular expressions are preserved exactly so behaviour is identical.

Smaller JavaScript means fewer bytes over the wire, shorter parse-and-compile time on the browser, and faster Time-to-Interactive — especially on mobile and low-end devices where the JS engine is the bottleneck. The OpenFormatter minifier is built around a state machine: it walks the source character-by-character, tracking whether it is inside a string, regex, or comment, and decides which whitespace can be safely removed. The result is faithful to the input semantics for almost all practical code.

How to minify JavaScript — 4 steps

  1. Paste your JavaScript. Drop a script, module, snippet, or even an entire bundle into the Input panel. Click Load Sample to try a demo with strings, a regex literal, and a license comment.
  2. Toggle preservation options. Decide whether to keep the 'use strict' directive at the top and whether to preserve license comments (the /*! convention). Both are on by default.
  3. Click Minify. The state machine runs in your browser, strips comments and whitespace, and emits the compressed result. The size strip above shows original bytes, minified bytes, and percent reduction.
  4. Copy and ship. Click Copy to grab the minified JavaScript and paste it into your build artifact, inline <script> block, or CDN bundle.

Sample transformation

Before — 9 lines, 174 bytes

// Greet a user
function greet(name) {
  const message = `Hello, ${name}!`;
  console.log(message);
  return message;
}

// Run it
greet('Ada');

After — 1 line, 92 bytes

function greet(name){const message=`Hello, ${name}!`;console.log(message);return message}greet('Ada');

A 47% reduction in this example — comments removed, whitespace collapsed, the template literal preserved exactly. The script behaves identically when executed.

Whitespace & Comments

Line comments (//), block comments (/* */), indentation, blank lines, and optional whitespace around punctuation are all stripped. Identifier-adjacent whitespace is preserved as a single space to keep tokens apart.

Literal-Aware

String literals (single, double), template literals with ${} expressions, and regex literals are passed through unchanged. The state machine detects regex by inspecting the previous token — never confuses division for a regex.

Client-Side Only

JavaScript is minified entirely in your browser. API keys, business logic, and unreleased code never touch a network — open DevTools Network and click Minify to verify zero requests fire.

Common use cases

  • check_circleReducing JavaScript bundle size before deploying to a CDN (Cloudflare, Vercel, Netlify, S3 + CloudFront)
  • check_circleCompressing inline <script> blocks injected into HTML emails or marketing landing pages
  • check_circleSlimming a single-file utility script before publishing to a Gist, snippet host, or pastebin
  • check_circleReviewing minified third-party code in code reviews — round-trip via the JavaScript Pretty Print tool
  • check_circleCompressing JavaScript bookmarklets so they fit within browser-bookmark size constraints
  • check_circleReducing payload of a bundled service-worker or Cloudflare Worker script
  • check_circleOptimising a one-off analytics snippet, A/B-test variant, or feature-flag bootstrap script
  • check_circlePreparing JavaScript for embedding in a QR code or short URL where every byte counts

Three real-world wins from minifying JS

1. CDN payload reduction

A 200KB hand-written analytics library typically minifies to 90–110KB before gzip. After Brotli on the CDN, the wire size can be 25–35KB — a 6× reduction over the un-minified, uncompressed source. On a slow 3G connection that is the difference between blocking your TTI for 1.5 seconds and being a non-issue.

2. Inline-script slimming for HTML emails

Gmail clips emails over 102KB. If your transactional template uses an inline tracking pixel script, every comment and indent counts. A naive 4KB script with comments minifies to 1.5–2KB — and that headroom is what keeps the entire email under the clipping threshold.

3. Code-review round-tripping

A common review task is auditing a third-party widget that arrived as one long minified line. Pretty-print to read, then re-minify to confirm the byte-for-byte equivalence of the patch you intend to ship. The OpenFormatter minify + beautify pair are exact inverses for whitespace, so a clean diff confirms behaviour-preserving changes.

Minify vs uglify vs compress — clearing up terminology

The three terms get used interchangeably but mean different things in practice. Minification is the bytes-only transformation: remove comments and whitespace, leave identifiers alone. Uglification (the historic UglifyJS verb) adds variable mangling — renaming userAccountManager to n — and dead-code elimination. Compression normally refers to gzip or Brotli applied at the HTTP layer, which is orthogonal: you still want to minify before you compress. This tool is a strict minifier — it never renames identifiers, so the output remains a faithful, debuggable version of your source.

This tool vs terser, esbuild, SWC

When should you reach for a heavyweight minifier and when is a regex/state-machine tool enough?

  • eastterser — the de-facto JS minifier. Full AST, mangling, dead-code elimination, property shortening. Use in a build pipeline.
  • eastesbuild — Go-based bundler with a built-in minifier. 10–100× faster than terser at slightly larger output sizes.
  • eastSWC — Rust-based compiler used by Next.js and Parcel. Output competitive with terser, faster than esbuild on minify.
  • eastOpenFormatter (this tool) — heuristic state-machine in pure browser JS. Strips comments and whitespace safely; does not mangle. Use for quick one-off jobs and code-review round-trips.

Need to format, escape, or convert JavaScript?

OpenFormatter ships beautify, escape, unescape, and converter tools for JavaScript and TypeScript — all browser-side.

Frequently Asked Questions

What does this JavaScript minifier remove?

It strips three categories of bytes: (1) line comments (// ...) and block comments (/* ... */); (2) all unnecessary whitespace — runs of spaces, tabs, newlines, and blank lines collapse to nothing or to a single space when needed to keep tokens apart; (3) optional whitespace around punctuation like braces, parentheses, commas, semicolons, and operators. String literals, template literals, and regex literals are preserved exactly as written.

Will minification break my regex or template literals?

No. The minifier uses a state machine that detects regex literals by looking at the previous token (regex appears after operators, return, typeof, etc.) and reads them whole — including character classes that contain forward slashes. Template literals (backticks) preserve their interior whitespace and ${...} expressions exactly. Single and double-quoted strings are also passed through untouched.

How much size reduction is typical?

Hand-authored JavaScript with full indentation and developer comments commonly compresses 30–55% with whitespace stripping alone. Already-clean output from a build tool may see 10–20%. Combined with gzip or brotli on the server, the wire-size savings stack — but every byte saved before compression also saves browser parse time on low-end devices.

Is this minifier as good as terser or esbuild?

No. Terser, esbuild, and SWC parse JavaScript into an AST and perform real optimisations: variable mangling, dead-code elimination, constant folding, function inlining, and property shortening. This tool is a heuristic state-machine minifier — it strips comments and whitespace safely for almost all practical code, but it cannot rename variables or perform structural optimisations. Use this for quick one-off minification; use terser/esbuild in your build pipeline.

Does it preserve "use strict" and license comments?

Both are configurable via toggles above the editor. By default both are preserved. License comments are detected by the /*! prefix or by @preserve / @license markers inside a block comment, matching the convention used by terser, uglifyjs, and Closure Compiler. The "use strict" directive is restored at the top of the output if it was present in the input.

Will it correctly handle ASI (automatic semicolon insertion)?

Mostly. Newlines that would have triggered ASI between two statements are converted to semicolons or preserved as separators. Code that relies on quirky ASI corner cases (e.g. a function call across lines that begins with an open parenthesis) can break — the same caveat that applies to terser. Author defensive code with explicit semicolons if you intend to minify.

Is my code uploaded to your servers?

No. The minifier runs entirely in JavaScript inside your browser. Source containing API keys, internal logic, or unreleased product code never leaves the device — verify in your browser DevTools Network tab. There are no requests, no telemetry, and no rate limits.

Can I un-minify the output back to readable JavaScript?

Yes. Paste the minified result into our JavaScript Pretty Print or jsbeautifier tool and it will reformat the code with proper indentation. The two operations are exact inverses for whitespace, although comments removed during minification cannot be recovered.

JavaScript Minifier Online — Free JS Compressor & Whitespace Stripper