Convertur

JavaScript minifier

JavaScript minifier built on Terser. It strips whitespace and comments, shortens local names and drops dead code. Paste JS and copy the result.

Loading tool...

What this JS minifier does

It runs your code through Terser with compression and name mangling on. Whitespace, line breaks and normal comments are removed. Local variables and parameters get one or two letter names. Constant math like 2 * 60 * 60 is folded to 7200, and statements in a row are joined with commas. The result is usually one line of code that behaves the same as the original.

How to minify JavaScript

Paste your code into the input pane and click Convert. If Terser can't parse it, you'll see the error and the token it stopped at. Otherwise copy the minified code, or download it and save it as a .js file. Your code stays in this browser tab.

Why minify JavaScript

Every byte of a script has to be downloaded and parsed before it runs. Removing characters that only help human readers makes pages load faster. Minifying works alongside gzip or Brotli on your server. Compression shrinks repeated patterns, while minifying removes text that never needed to be sent. It's a normal step for production code, and a fast way to shrink a snippet, bookmarklet or embed script that has no build step.

What Terser removes and what it keeps

Terser only rewrites code when the result does the same thing. It removes code that can never run, such as an if (false) block or statements after a return. It also removes unused local variables and functions, and debugger statements. It keeps console calls, import and export statements, string contents and property names, so obj.userName is never shortened. Top-level names are kept too, because your input is treated as a script whose globals other scripts may use. Comments that start with /*! or contain @license or @preserve are kept, so copyright notices stay in place.

Modern syntax, TypeScript and JSX

Terser understands modern JavaScript: ES modules, classes with private fields, arrow functions, async and await, optional chaining with ?. and nullish coalescing with ??. It minifies that syntax as written and doesn't transpile it, so the output runs in the same browsers as your source. It can't parse TypeScript types or JSX. Compile those to plain JavaScript first with tsc, esbuild, Babel or your bundler, then minify the result. When the input can't be parsed, the tool shows Terser's error, such as "Unexpected token: punc (:)", so you can find the bad character.

Powered by Terser

Terser is the default JavaScript minifier in webpack 5 production builds and an option in Vite and Rollup. This tool uses its standard compress and mangle settings. Bundlers often add extras, such as top-level mangling for ES modules or several compression passes, so their output can be a little smaller.

Before you ship minified code

Minified JavaScript is a build output. Don't edit it by hand. A few habits keep it safe to deploy:

  • Keep the readable source in version control and minify it again after every change.
  • Load the minified file in your page and test it before you replace the original.
  • Start license headers with /*! so they are kept.
  • Serve the file with gzip or Brotli and a long cache lifetime, and change the file name when the contents change.
  • Minifying is not obfuscation. A beautifier brings back the indentation, though the original local names and comments are gone for good.

Before you start

Input: JS and MJS. Output: Minified JavaScript. The settings appear before anything runs, so you can check them first. Your original file is never changed.

The value you enter is processed in your browser. Still test the output where it will be used. Clean formatting does not prove the data is safe or correct.

Keep the original until you have opened and checked the result. The work happens in this browser tab, so the size you can handle depends on your device's memory, your browser and the file itself.

How to use the JavaScript minifier

  1. Paste your JavaScript into the input pane.
  2. Click Convert to minify it with Terser.
  3. If an error appears, fix the syntax at the token shown, or compile TypeScript and JSX to JavaScript first. Then convert again.
  4. Copy the minified code, or download it and save it with a .js extension.

Last updated · How we build and check tools · Report an error

Learn more

Related tools

JavaScript Minifier FAQ