TextyConverterbeta
⌘K

JavaScript Minifier

Minify JavaScript using Terser — the same minifier used by Webpack, Rollup, and Next.js. Browser-only.

0 characters
0 characters

About JavaScript Minifier

The JavaScript minifier uses Terser, the industry-standard minifier that ships with every major bundler. It compresses your code by mangling local variable names, removing whitespace and comments, and applying dozens of small transformations that produce semantically identical but shorter output. The result is what production bundles look like.

When to use it

  • Producing a hand-minified script to inline in HTML
  • Estimating the production-bundle size of a code snippet
  • Squeezing a small script down to fit in a constrained context (bookmarklet, embed)
  • Stripping comments and console.log calls from a snippet before sharing
  • Generating a single-line script for a CSP-restricted environment

How it works

Terser parses the JavaScript into an AST, then runs a configurable compress pass (dead code elimination, constant folding, and ~30 other optimizations) followed by a mangle pass that shortens local variable names. Finally it re-emits the AST as compact source. Top-level names are preserved by default so the minified script remains usable as a library.

Examples

Comments, whitespace, and intermediate variable removed
// double a number
function double(n) {
  const result = n * 2;
  return result;
}

console.log(double(21));
function double(n){return 2*n}console.log(double(21));

Frequently asked questions

Does the minifier change my code's behavior?
Terser is designed to be semantics-preserving for well-behaved code. It does make assumptions (no eval-rewriting of local names, no use-before-declare hacks) that hold for almost all modern code. Anything pathological should be tested.
Are top-level names mangled?
No, top-level names are preserved. Local variables inside functions are shortened. To mangle top-level too, integrate Terser into your build with toplevel: true.
Does it support modern syntax (ES2022+, classes, modules)?
Yes. Terser is updated to track the latest ECMAScript standard. Top-level await, private class fields, decorators (per current proposal), and import/export are all supported.
What about source maps?
This UI doesn't expose source-map output, but Terser supports them when used as a library. For debuggable minified code, integrate Terser directly into your build pipeline.
Is my JavaScript sent to a server?
No. Terser runs entirely in your browser. The page lazy-loads Terser on first use; subsequent calls are instant.

Related tools