Skip to main content
Premier SEO Services

Developer tools

JavaScript Minifier

Minify JavaScript with Terser: whitespace and comments removed, local variables shortened and dead code dropped. You see the original, minified and gzipped sizes side by side.

  • Runs in your browser
  • Free, no sign-up
  • Unlimited use
  • Updated 30 September 2026

JavaScript Minifier

Paste your text — the result updates as you type

  • The code must be valid JavaScript (ES2020 or earlier syntax is safest); TypeScript and JSX must be compiled first.
  • No source map is produced.

How to use the JavaScript minifier

  1. 1Paste your script into the JavaScript box, or press Example.
  2. 2Keep Shorten variable names and Optimize code ticked for the smallest result. Tick Remove console.* calls for production builds.
  3. 3Leave Code type on Detect; choose ES module if the file uses import/export but the detection misses it.
  4. 4Press Minify JavaScript. The footer shows the saving and the gzipped sizes; press Copy or Download (script.min.js).

Example

Input
// Greeting helper
function greet(name) {
  if (!name) {
    return 'Hello, stranger';
  }
  const greeting = 'Hello, ' + name + '!';
  return greeting;
}
console.log(greet('Ada'));
Output
function greet(e){return e?"Hello, "+e+"!":"Hello, stranger"}console.log(greet("Ada"));

Saved 52% (182 B → 87 B); gzipped 147 B → 96 B. The parameter name became e and the if/return pair became one conditional expression. greet keeps its name because it is a top-level function another script could call.

Whitespace removal vs mangling

Minification works in three layers, each with its own option:

  1. Whitespace and comments are always removed. Comments starting with /*! or containing @license are kept when Keep license comments is ticked, because many licenses require the notice to stay with the code.
  2. Shorten variable names (mangling) renames local variables and parameters to one or two letters. Top-level names in a classic script are left alone, since other scripts on the page may use them.
  3. Optimize code (compression) rewrites code into shorter equivalents: dead branches removed, constant expressions folded, if statements turned into && or ?:. It runs two passes.

If the minified file throws errors that the original didn't, try again with Optimize code off to find out which layer is responsible.

Source maps

A source map lets browser developer tools show the original file, with real names and line numbers, when an error happens in minified code. This page doesn't create one, because a source map is only useful if it is deployed next to the minified file and kept in step with it, which is a build-tool job. Webpack, Vite, esbuild and Rollup all generate source maps with a single setting. Use this tool for one-off scripts, snippets for a CMS or tag manager, and checking how much a file would shrink.

Gzip and Brotli: why transfer size differs

Servers usually compress text before sending it, with gzip or Brotli. Compression already removes much of the repetition that whitespace adds, so the gain from minifying is smaller over the network than on disk. In the example, minifying saved 52% of the raw size but 35% of the gzipped size.

The footer shows both numbers. The gzipped figure (level 9) is close to what visitors download from a server with gzip enabled; Brotli is usually a little smaller still. Minifying and compressing together beat either one alone, because a mangled, comment-free file also compresses better.

When your build tool already minifies

If your site is built with a bundler (Vite, Next.js, webpack, Parcel), production builds are already minified, usually with Terser or esbuild. Minifying that output again gains little. Check before you add a step: open the deployed .js file. If it is one long line with short variable names, it is minified.

WordPress and other CMSs often serve scripts unminified. A caching or optimization plugin can minify them, or you can minify a theme's custom script here and upload the .min.js version. Measure the effect with the website speed test.

Is my text private?

This tool runs entirely in your browser. Your text is not uploaded to our servers.

Sources

Questions about the JavaScript minifier

Can minification break my code?

Rarely, and usually because the code relies on function or class names at runtime (fn.name) or uses eval. Terser avoids renaming in scopes that contain eval. If something breaks, minify again with Optimize code off, then with Shorten variable names off.

Should I minify if my server uses gzip?

Yes. The gain is smaller than the raw numbers suggest, but minified code still transfers smaller and parses faster, and comments never need to reach the browser.

Can I get a source map?

Not from this page. Generate source maps in your build tool so they stay in sync with the deployed file.

Last updated 30 September 2026Maintained by Premier SEO Services

Report a problem