Skip to main content
UtilityStack

JS Minifier — strip comments and whitespace

Paste a JavaScript file and get a minified version with comments and redundant whitespace removed. Strings, regexes and template literals are preserved verbatim.

Source: 269Minified: 17099 bytes (37%)
Source JavaScript
Minified
function greet(name){if(!name){return"Hello,stranger!";}return"Hello,"+name+"!";}const users=["Alice","Bob","Charlie"];users.forEach(function(u){console.log(greet(u));});

This is a lightweight minifier — comments stripped, whitespace collapsed. For aggressive optimisation (renaming, dead-code elimination), use Terser or esbuild in your build pipeline.

What does this minifier do?

It runs a single character-by-character pass over your JavaScript, removing line and block comments, collapsing whitespace runs to a single space (or zero where safe), and stripping spaces around punctuation. String literals (single, double, template), regular expression literals and license comments (/*! ... */) are preserved exactly as written.

This is a lightweight minifier, not a full optimiser. Tools like Terser, esbuild's --minify and SWC also rename variables, eliminate dead code, fold constants and shorten expressions — gains we don't aim for here. Use this when you need a quick, reliable byte reduction without setting up a build chain; reach for Terser when shipping production bundles.

How to use this tool

  1. Paste your JavaScript into the left pane, or click 'Load sample' to see the tool work on an example script.
  2. The minified output appears on the right instantly. The header shows source vs minified byte counts and the percent saved.
  3. Click Copy to grab the minified script. Verify it still parses by running it through Node, your browser console, or your test suite before shipping.

Frequently asked questions

Is the output safe to use directly?

For modern hand-written JavaScript, yes — strings, regexes and template literals are preserved exactly. As with any minifier, run your tests against the minified output before deploying. Rare edge cases (semicolon-insertion-sensitive code, IIFE comma operators) can be sensitive to whitespace removal.

Does it support ES2022+ syntax?

Yes. The minifier doesn't parse the AST, it works at the lexical level, so any valid JavaScript syntax — class fields, optional chaining, top-level await, decorators — passes through unchanged.

What about source maps?

This tool does not emit source maps. If you need to debug minified JS in production, generate maps with esbuild --sourcemap, Terser, or your bundler instead.

Can I minify TypeScript?

Strip types first (tsc, esbuild, swc) to get plain JS, then minify. Pasting TypeScript directly will technically work — comments and whitespace get stripped — but the output keeps the type annotations as syntax errors.

Why is the saving smaller than I expected?

Pre-formatted code (Prettier, your editor's default) leaves less whitespace to remove. Minimal comments mean less to strip. The biggest savings come from heavily-commented hand-written modules or ESM-style code with deliberate spacing for readability.

Common use cases

Where stripping JS bytes pays off in seconds.

Inline scripts in HTML

Small <script> blocks (analytics snippets, feature flags, user-message banners) get smaller and parse faster after minification — every byte saved is delivered on every visit.

Bookmarklets

Bookmarklets ship as single-line javascript: URLs with a ~2000-char limit in some browsers. Minify your draft to fit the limit while keeping a readable source separately.

Email signature scripts

Some legacy email systems allow JS in templates. Inlined and minified scripts there win twice — bytes and parser cost.

Embedded snippets in markdown / blog posts

When pasting a code snippet that's also functional (a Stack Overflow style demo), minify it after you copy the readable version so the page itself stays light.

Tips and shortcuts

Habits that keep JS lean from authoring through deployment.

Use a real bundler for production

Terser and esbuild --minify do everything this tool does plus dead-code elimination, identifier renaming, and constant folding — typically 2-3× more savings on real codebases.

Keep readable source

Author with comments and whitespace; minify on deploy. Editing minified code by hand introduces subtle bugs that don't show up until production.

Beware of asi-sensitive code

Code like 'a = b\n[1, 2, 3].forEach(...)' relies on automatic semicolon insertion. Removing the newline can change semantics. If your code uses ASI heavily, prefer Terser which understands the parser rules.

Minify after transpilation

If your build chain includes Babel or SWC, run minification after transpilation. Minifying first-then-transpiling can produce bloated output because the transpiler may re-add whitespace.

Outils similaires