go-supertools
Developer & Data Tools

JS Minifier

Minify JavaScript in your browser with Terser, with before/after byte sizes, percent saved and clear syntax errors.

Runs in your browser Your input never leaves your device.

Report a problem with this tool

About this tool

Paste JavaScript and get a minified version using Terser, running entirely in your browser. It removes whitespace and most comments, compresses expressions and can rename local variables (optional). Comments that start with /*! are kept, since they usually hold a licence. You see the size before and after in bytes and the percentage saved. Syntax errors are shown with the line and column. By default top-level names are not renamed or removed, so global functions keep working. If you tick "Treat as ES module", the top level is treated as private to the module: top-level names can be renamed, and functions that are not used or exported can be removed. Always test minified code before shipping.

How to use it

  1. Paste your JavaScript into the input box.
  2. Choose whether to rename local variables or treat the code as an ES module.
  3. Press Minify.
  4. Copy the output and check the byte sizes.

What the minifier does to your code

Whitespace and comments
Line breaks, indentation and comments are removed. Comments starting with /*! stay.
Compress
Expressions are rewritten in shorter forms that behave the same, for example if (a) { b(); } becomes a&&b(), and dead code after a return is dropped.
Rename local variables
Names inside functions become single letters. Top-level names are left alone unless the code is treated as an ES module.
Treat as ES module
Allows import and export, enables strict mode rules, and lets the minifier rename or drop unused top-level code, because a module's top level is not global.

Minify and compress: both help

Minifying removes characters the browser does not need. Gzip or Brotli compression, which most web servers apply when sending a file, then shrinks what is left. The two stack: a minified file still compresses, and a compressed file is smaller if it was minified first. The Gzip Test shows whether a site compresses its responses.

Before you ship minified code

  1. Keep the original source. Minified code is not meant to be edited.
  2. Test the minified file in the browsers you support.
  3. If something breaks, retry with Rename local variables off to see whether renaming is the cause.
  4. This tool does not produce a source map. For production builds, a bundler that runs Terser with source maps makes errors easier to trace.

Common problems

Syntax error shown
Fix the reported line and column. If the code uses import or export, tick "Treat as ES module".
Output behaves differently
Untick "Rename local variables" and retest; code that depends on function or variable names can break when they are renamed.
Very little size saved
Code that is already minified or has few comments and little whitespace has little left to remove.

Frequently asked questions

Is minified JavaScript secure or hidden?

No. Minified code is harder to read but anyone can reformat it with a formatter such as the JS Formatter. Do not put secrets in client-side code.

Can it minify CSS or HTML?

No, this tool only accepts JavaScript. Use the CSS Minifier or the HTML Minifier.