JavaScript Minifier

Strip comments and whitespace to shrink your JS.

Free JavaScript minifier — remove comments and collapse whitespace to shrink .js files. Strings, template literals and regex are preserved. Runs entirely in your browser, nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

Does it rename variables or mangle names?

No. This is a safe "obvious wins" minifier — it removes comments and collapses whitespace but never renames identifiers or rewrites your code, so valid input stays valid.

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.

What “minification” actually means

Minification is the process of removing characters from source code that are meaningful to a human reader but irrelevant to a JavaScript engine. The engine doesn’t care how many spaces you used, what you named your variables, or whether you added a comment explaining the algorithm — it just executes instructions. Removing that extra content shrinks the bytes that travel over the network and the parser has to read.

This tool covers the safe, deterministic layer of minification:

RemovedEffect
Line comments (//…)No impact on execution
Block comments (/*…*/)No impact on execution
Redundant whitespaceNo impact on execution
Newlines between statementsNo impact on execution

What it does not do — and why that is intentional:

  • No variable renaming / mangling. Renaming longVariableName to a is the biggest win production minifiers like Terser or esbuild achieve, but it requires building a full AST and symbol table. This tool uses a single-pass tokenizer, which is deliberately simpler and runs without dependencies in the browser.
  • No dead code elimination. Removing unreachable branches requires control-flow analysis.
  • No constant folding. Replacing 1 + 2 with 3 requires expression evaluation.

For production builds, use Terser, esbuild, or Rollup with a minify option. For quick snippets, pasted code, email attachment limits, or reading someone else’s already-minified code (use the JavaScript Formatter for that), this tool is the fastest option.

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.

Worked 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 (it’s inside a string literal), and the space in return greeting is kept because both sides are word characters — removing it would join them into returngreeting.

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