JavaScript Minifier

Shrink a JavaScript file or snippet by removing comments and whitespace, shortening local names and applying safe compression. The tool uses the open-source Terser parser inside your browser, shows the size before and after, and points to the exact line and column when your code has a syntax error.

Format & Validate Runs in your browser

Minify Your JavaScript

Your code is parsed and compressed in this page by the Terser library. It is never executed and never uploaded.

How to Use the JavaScript Minifier

  1. Paste your JavaScript into the box, or keep the sample to see how it works.
  2. Choose options: mangle renames local variables, compress simplifies code, and top-level renaming is off by default because other scripts may rely on global names.
  3. Press Minify and compare the original and minified sizes.
  4. Use Copy or Download to take the result as script.min.js.

About This Tool

Front-end developers preparing a small script for production, people embedding a snippet in a page or bookmarklet, and anyone who wants to see how much a build step would save.

Input: JavaScript (.js)  ยท  Output: Minified JavaScript.

Features and Limitations

Features

  • Parses the code with Terser; the code is never run.
  • Shows original size, minified size, bytes saved and percentage.
  • Reports syntax errors with line and column.
  • Optional ES-module mode for code that uses import and export.
  • Keeps /*! ... */ and @license comments if you need to retain a licence notice.

Limitations

  • No source map is produced, so debugging minified code in the browser is harder.
  • Mangling and compression can break code that depends on function names, eval or Function.prototype.toString.
  • Very large files (several megabytes) may make the tab unresponsive for a few seconds; the tool accepts up to 1 MB.
  • The result is syntax-checked by the parser but not tested against your application, so run your own tests.
  • Results are computed in your browser; nothing you enter is sent to a server.

Example

The sample code is 321 bytes. With the default options the comments and whitespace disappear and addNumbers(firstNumber, secondNumber) becomes addNumbers(r,e), leaving about 152 bytes, roughly 53% smaller.

Frequently Asked Questions

Is my code uploaded or executed?

No. Terser parses your text into a syntax tree, rewrites it and prints it again. Nothing is evaluated and nothing leaves your browser.

What is the difference between mangle and compress?

Mangling shortens the names of local variables, parameters and functions. Compressing rewrites expressions (for example removing unreachable code or folding constants). You can switch either off independently.

Why is top-level renaming off by default?

Top-level variables and functions are often used by other scripts or by inline HTML handlers. Renaming them would break those references, so enable it only for self-contained code.

Why do I get an error for import or export?

Those keywords are only valid in ES modules. Tick the ES-module option and minify again.

Does it support modern syntax like optional chaining and classes?

Yes. Terser understands current ECMAScript syntax, including async functions, optional chaining, nullish coalescing and class fields.

Related Tools

More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.