JavaScript Minifier

Minify JavaScript by stripping comments and whitespace — no upload

Free JavaScript minifier — strip comments and collapse insignificant whitespace while preserving strings, template literals, and regex. Shows the size reduction percentage. Runs entirely in your browser; no code is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How does the minifier shrink my code?

It removes line and block comments and collapses runs of insignificant whitespace. A single space is kept only where it separates two identifier characters, such as between a keyword and a variable, so the meaning of the code is preserved exactly.

A JavaScript minifier reduces file size by removing everything a browser does not need to run your code: comments, indentation, and blank lines. Smaller files download faster and parse quicker, which improves page-load performance. This tool minifies your JavaScript in the browser and shows exactly how many bytes you saved, with no upload.

How it works

The minifier scans your source one character at a time, acting like a small tokenizer. When it encounters a string, template literal, or regular-expression literal, it copies the entire literal verbatim — quotes, escapes, and all — so nothing inside is altered. The trickiest case is the / character, which can start either a division or a regex; the tool decides based on the previous significant token (for example, a / after return or ( begins a regex), exactly as a JavaScript parser would.

Outside of literals, line comments (//) and block comments (/* */) are dropped entirely. Runs of whitespace are then collapsed: a single space is preserved only when it sits between two identifier characters, such as in return value where removing the space would merge two tokens. Everywhere else the whitespace is removed.

What it does not do

Unlike Terser or UglifyJS, this tool does not rename identifiers, fold constants, or eliminate dead code, because those transformations require a full AST and can subtly change behaviour. The trade-off is safety and readability: the output behaves identically to your input. For maximum compression in production, pair this with gzip or Brotli, which together typically beat aggressive renaming on real-world code. Everything runs locally in your browser.

When to use this tool

This minifier is ideal for:

  • Inline scripts in HTML pages where you want to reduce bytes without a build pipeline.
  • Quick one-off minification of utility scripts, bookmarklets, or code snippets to share.
  • Checking how much whitespace and comments inflate a file before deciding whether a full build tool is worth the setup.
  • Safe minification of proprietary code — because nothing leaves the browser, confidential source never touches an external server.

For production applications with many large JavaScript files, a full build tool such as Vite, Webpack, or Rollup wraps Terser automatically and adds tree shaking on top of comment/whitespace removal. Use this tool when you want a fast, safe, zero-install answer.

Illustrative worked example

Suppose you have a small configuration helper:

// Map an environment name to an API base URL
function getApiUrl(env) {
  // Default to production
  if (env === 'staging') {
    return 'https://staging.example.com';
  }
  return 'https://api.example.com';
}

After minification:

function getApiUrl(env){if(env==='staging'){return 'https://staging.example.com';}return 'https://api.example.com';}

The comments are gone, the blank lines collapsed, and the spaces inside the string literals are untouched. The function behaves exactly the same.

Common edge cases

  • Template literals with embedded expressions: the tool preserves the entire backtick block, including ${...} expressions, verbatim.
  • Regex after a keyword: /pattern/gi following return, typeof, or = is correctly identified as a regex, so its content is never touched.
  • No minification of //-style comments inside strings: a string like "// not a comment" is copied as-is because the tokenizer knows it is inside a string literal.