Skip to content

JavaScript Minifier

Compress JavaScript for production with Terser, right in your browser.

Input
897 B
Minified
470 B
Saved
427 B (47.6%)

JavaScript input

Tab inserts indentation. Press Escape, then Tab, to move focus out of the editor.

Minified JavaScript

How to minify JavaScript

  1. Paste your JavaScript on the left, or open a .js file.
  2. The minified code appears on the right, with the original size, the new size and the percentage saved above it.
  3. Keep Compress and Shorten names on for the smallest result, and choose what happens to comments.
  4. Copy the result or download it as script.min.js.

Small scripts update as you type. For large files, press Minify JavaScript — the work happens in a background worker, so the page stays responsive.

Example

Original
// Greet every user by name
function greetUsers(userList) {
  const greetings = userList.map((user) => `Hello, ${user.name}!`);
  return greetings.join("\n");
}
Minified
function greetUsers(e){return e.map(e=>`Hello, ${e.name}!`).join("\n")}

The comment and whitespace are gone, the parameter userList became a single letter, and the temporary greetings variable was folded into the return statement. The function name greetUsers stays, because other scripts may call it.

Powered by Terser

The minifier is Terser, a widely used JavaScript minifier. It parses your code into a syntax tree, so it understands modern JavaScript — classes with private fields, async/await, optional chaining, nullish coalescing, template literals, regular expressions and ES modules — and it refuses code that doesn't parse: you get the error with its line and column instead of broken output.

Use cases

  • Shrinking a script for a site without a build step.
  • Minifying a bookmarklet or an inline snippet for an HTML page.
  • Checking how much a file would shrink before adding a build tool.

Related tools

To read minified code, use the JavaScript formatter. Shrink the rest of your page with the CSS minifier and the HTML minifier, and test scripts in a real page with the HTML compiler.

Frequently asked questions

Which minifier does this use?
Terser, the minifier used by many build tools. It runs in a background worker in your browser, so large files don't freeze the page and your code isn't uploaded.
Is minified code safe to use?
Terser only applies transformations that keep behaviour the same. Global names of classic scripts and exported names of modules are never renamed, so other scripts can still use them. Test minified code before deploying it, as with any build step.
What do Compress and Shorten names do?
Compress applies safe optimisations such as removing unreachable code and simplifying expressions. Shorten names renames local variables and functions to short names. Turn both off to only strip whitespace and comments.
What happens with syntax errors?
Nothing is produced: you get the error message with its line and column instead, so broken JavaScript is never passed on silently.