JavaScript Minifier

Strip comments and whitespace to shrink your JS.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

Minify JavaScript in your browser

Paste any JavaScript to strip comments and collapse whitespace down to a compact single-line result. This is a conservative, dependency-free minifier: it does the obvious size wins without renaming variables or rewriting your code, so valid input always stays valid. Use it for quick snippets, pasting compact code, or trimming a file under an upload or email size limit.

How it works

The minifier scans your source character by character in a single pass and:

  • removes line comments (//…) and block comments (/*…*/);
  • copies the contents of string literals, template literals and regular expressions verbatim, so a // or space inside a string is never touched;
  • collapses runs of whitespace, keeping a single space only where it is needed to separate two word characters (for example return x).

To avoid mangling regular expressions, it tracks the last meaningful token: a / starts a regex only when the previous token cannot end an expression (after operators, brackets, or keywords such as return, typeof and in), otherwise it is treated as division. After minifying it reports the new character count and the percentage saved.

Example

This input:

// Greets a user
function greet(name) {
  const greeting = "Hello, " + name + "!";
  return greeting;
}

becomes:

function greet(name){const greeting="Hello, "+name+"!";return greeting;}

The comment is gone, indentation is collapsed, the space inside "Hello, " is preserved, and the space in return greeting is kept because both sides are word characters.

Everything runs locally — nothing is uploaded, which keeps proprietary source private.

Ad placeholder (rectangle)