DevToolsmith

JavaScript Minifier

Paste JavaScript to minify it with Terser: whitespace and comments removed, names shortened, code simplified. License comments stay, a source map is one click away, and you can see the real gzip savings.

Runs 100% in your browser — nothing is uploaded

Automatically minifies up to 1 million characters.

JavaScript
Tip: drop a file here492 chars · 492 bytes · 17 lines
Minified JavaScript
0 chars · 0 bytes · 0 lines

Example

Before
// Returns the price with tax, rounded to cents
export function withTax(price, rate = 0.2) {
  const total = price * (1 + rate);
  return Math.round(total * 100) / 100;
}
After
export function withTax(t,n=.2){const o=t*(1+n);return Math.round(100*o)/100}

What minification does

StepEffect
Whitespace and comments Line breaks, indentation and ordinary comments are removed. /*! comments are kept for licenses.
Shorter names Local variables, parameters and (in modules) top-level functions get one-letter names. Exported names and object properties keep theirs.
Compression Constant expressions are folded, unreachable code is dropped, if/else becomes ?: or &&, and repeated passes find more.
Syntax true becomes !0, undefined becomes void 0 and string quotes are picked to need the fewest escapes.

Minify on the command line

# Terser, the minifier used here (and by webpack's default production build)
npx terser app.js --module --compress --mangle --source-map "url='app.min.js.map'" -o app.min.js

# esbuild: much faster, slightly larger output
npx esbuild app.js --minify --sourcemap --outfile=app.min.js

Bundlers such as Vite, webpack and Next.js already minify production builds, so this tool is most useful for standalone scripts, snippets and checking what a minifier does. To read minified code, use the JavaScript Formatter.

Frequently asked questions

How do I minify JavaScript?

Paste your code or drop a .js file into the minifier above. It runs Terser in your browser, removes whitespace and comments, shortens local names and simplifies the code. The table under the output shows the size before and after, with and without gzip.

Is minified JavaScript safe to use?

Yes, Terser only makes changes that keep the behaviour the same. Two things to watch: code that reads function names at runtime (fn.name) sees the short names, and code that relies on global names should be minified with ES module turned off so those names are kept.

What does the ES module option do?

With ES module on, the code is treated as a module: it is strict, and top-level functions and variables are private to the file, so they can be renamed. Turn it off for classic scripts loaded with a plain <script> tag, where top-level names are globals other scripts may use.

What is a source map and do I need one?

A source map links the minified code back to the original, so browser dev tools and error trackers such as Sentry show readable file names, lines and variable names. Tick Source map and upload the .map file next to the minified file, or only to your error tracker if you don’t want to publish the source.

How much smaller will my JavaScript get?

Typically 40–70% before gzip, depending on how much of the file is comments and long names. Servers compress text with gzip or Brotli anyway, so the gzipped numbers in the table are what users actually download.