Modern Niche World MNW

JavaScript Minifier

Paste JavaScript, choose how far to go, and get smaller code from terser, run in this page. Syntax errors are shown with their line and column.

Settings

The newest syntax terser may write. It never turns newer syntax into older.

0 bytes

Paste JavaScript, then press Minify.

Your code stays on your device: terser runs in this page, and nothing is sent or saved. Up to 1 MB.

Smaller JavaScript, made by terser in your browser

Minified JavaScript loads and parses faster, which matters most on phones. This page runs terser, the minifier many build tools use, directly in your browser. It suits a single script for a small site, a bookmarklet or a snippet you embed; for a whole project, a build tool on your computer does the same job on every change.

How to use it

  1. Paste your code into the box.
  2. Choose the settings. The defaults are a safe start for most scripts.
  3. Press Minify. The first time, the minifier loads from this site, which takes a moment.
  4. Copy the result or download it as a .js file, then test it before you ship it.

What the settings do

  • Compress rewrites code into shorter equivalents: unused code goes, constant expressions are worked out, and if statements can become shorter expressions.
  • Rename local names replaces names inside functions with short ones. Global names stay, since other scripts may use them, unless you mark the code as an ES module.
  • ES module tells terser the code is a module, which also allows import, export and await at the top level.
  • ECMAScript version lets terser use newer syntax, such as arrow functions, where it saves space. Choose the oldest version your visitors’ browsers need.

When something goes wrong

If your code can’t be read, nothing is minified. You’ll see the message with its line and column, and the lines around it with a mark under the spot. Fix it in your original file and run it again.

Good practice

  • Start with the defaults, and turn on ES module only for code that really is a module.
  • Test the minified file in the browsers your visitors use before you replace the original.
  • Save it as name.min.js next to the readable file, so it’s clear which one to edit.

Good to know

  • No source map is made, so error messages from the minified file point to its single long line. Keep your original for debugging.
  • Up to 1 MB: larger files can keep a browser tab busy for a long time.
  • Shrinking the rest of a site? The Image Compressor handles pictures, often the largest files.

Frequently asked questions

What does it use to minify?
terser, a widely used open-source JavaScript minifier (BSD license). It runs inside this page, on your device; it’s loaded from this site the first time you press Minify.
Will the minified code behave the same?
It should: terser only makes changes that keep what the code does. Code that reads its own function names, or uses eval or with, can need care; turn on “Keep function and class names” if your code relies on names, and test the result before you ship it.
Does it convert modern JavaScript for older browsers?
No. The ECMAScript version only sets the newest syntax terser may use while shortening your code. It never rewrites newer syntax into older; a transpiler such as Babel does that.
Is my code uploaded?
No. Your code stays in this page and nothing is sent or saved. The only download is the minifier itself, from this site, once.