ToolHub

JavaScript Minifier

Minify JS to shrink your files

JavaScript Minifier

Minifying JavaScript renames variables, drops comments, and strips whitespace to shrink the file and speed up downloads. Powered by Terser, running entirely in your browser.

Overview

Minify JavaScript to shrink and speed up your code

Minifying JavaScript removes everything a browser does not need to run the code: comments, line breaks, and indentation. A good minifier goes further and renames local variables to short names and folds away dead code, so the file gets dramatically smaller without changing what it does. Smaller scripts download faster and parse quicker, which directly improves page load speed and Core Web Vitals.

ToolHub JavaScript Minifier uses Terser, the same engine behind many modern build tools, and shows exactly how many bytes you save. Everything runs in your browser.

Step-by-step

How to minify JavaScript

  1. 1

    Paste your code

    Drop your JavaScript into the input panel. The example shows the kind of source you can paste.
  2. 2

    Watch it minify

    The minified output appears instantly on the right, along with the original size, the new size, and the percent saved.
  3. 3

    Copy the result

    Click copy to grab the minified code, ready to drop into a script tag or a bundle.

Smaller, faster

What minifying does to your code

  • Strips comments and JSDoc blocks
  • Removes line breaks and indentation
  • Renames local variables and function arguments to short names (mangling)
  • Drops unreachable and dead code
  • Folds constant expressions and simplifies where it is safe to do so

The code behaves identically, but the file is often 30 to 60 percent smaller. Combined with gzip or Brotli compression on your server, the savings stack up.

Use cases

When to minify

Quick snippets

Minify a small script or inline snippet before pasting it into a page or template.

Embeds and widgets

Ship the smallest possible code for third-party embeds and tracking snippets.

Learning and inspection

See how a minifier transforms your source and how much each pattern costs in bytes.

Legacy projects

Minify standalone files in projects that do not yet have a build pipeline.

Email and size-limited contexts

Squeeze a script under a byte budget for places where every kilobyte matters.

Production builds

For whole projects, let your bundler minify automatically and keep an unminified source.

Tips and best practices

  • Always keep an unminified source for editing and version control.
  • Minify as the last step, after transpiling and bundling.
  • For whole projects, let your build tool (Vite, esbuild, webpack) minify automatically.
  • Minified code is hard to debug. Use source maps in real builds to map errors back to your source.
  • Minification is not obfuscation. It is reversible enough that it does not hide your logic.

Common questions

How much smaller does minified JavaScript get?

Typically 30 to 60 percent before compression, depending on how many comments, long variable names, and whitespace the source has. The tool shows the exact percentage for your code.

Will minifying change how my code behaves?

No. Terser only renames locals and removes characters that do not affect execution. The minified output runs the same as your source.

What is the difference between minifying and obfuscating?

Minifying makes code smaller and is a normal production step. Obfuscating deliberately makes code hard to read to deter copying. Minified code is still understandable with effort, so do not rely on it for secrecy.

Why did I get a syntax error?

Terser parses your code before minifying, so it reports the same syntax errors a browser would. Check the line it mentions for a missing bracket, comma, or quote, then minify again.

100% private

Privacy and security

Your JavaScript is minified locally in your browser using Terser. Nothing is uploaded or sent over the network, so it is safe for private and proprietary code.

Related tools

Frequently asked questions

How much smaller will my file be?

It depends on the code, but minification commonly cuts JavaScript size by 30 to 60 percent before gzip.

Does it change how my code runs?

No. Minification only removes whitespace, shortens local names, and drops dead code. The behavior stays the same.

Is my code uploaded anywhere?

No. Minification runs entirely in your browser.