Ttooleras
📦

JavaScript Minifier

Minifiers

Compress JavaScript for production — Terser-style minification, 30-50% smaller. Free, private — all processing in your browser.

Advertisement

The JavaScript Minifier compresses JavaScript code for production deployment — typically 30-50% smaller than source. Uses Terser-style optimizations: remove whitespace and comments, shorten variable names (mangling), dead code elimination, constant folding, function inlining, and unused imports removal. Handles modern JavaScript (ES2015+ syntax), TypeScript output, JSX compilation output, and CommonJS/ESM modules. Produces code that runs identically to source but dramatically smaller for network transfer.

JavaScript minification is critical for production performance — JS bundles are typically the largest and most render-blocking resource on a page. A 500KB source bundle minified to 200KB saves 300KB per page load, improving Time to Interactive (TTI) and First Input Delay (FID). Combined with gzip/brotli compression, the wire transfer can be 90%+ smaller than source. Modern build tools (Webpack, Vite, Rollup, esbuild) minify automatically — this tool is for ad-hoc minification: single files, legacy codebases, browser-loaded scripts outside a build pipeline, or understanding what minification does to your code.

JavaScript Minifier — key features

Terser-level compression

Variable mangling, dead code removal, constant folding, function inlining. 30-50% reduction.

Preserves semantics

Minified code runs identically to source. Variable names changed but behavior unchanged.

Modern JS support

ES2015+ (arrow functions, classes, async/await, spread/rest, optional chaining, nullish coalescing).

License comment preservation

Comments with /*! are kept. Regular /* */ removed.

Size comparison

Before/after size and percentage savings. Verify savings match expectations.

Mangle toggle

Enable/disable variable name shortening. Disabled preserves readability (less savings).

Dead code elimination

Unused variables, unreachable code blocks removed automatically.

100% client-side

Your JavaScript (possibly proprietary business logic) processed in your browser.

How to use the JavaScript Minifier

  1. 1

    Paste JavaScript

    Source JS — can be from a single file, bundle, or copy-pasted function.

  2. 2

    Configure options

    Mangle variables? Preserve license comments? Keep function names?

  3. 3

    Click Minify

    Minified JS appears with size statistics.

  4. 4

    Verify works

    Test minified JS in your target environment. Usually identical to source, but edge cases exist.

  5. 5

    Copy or download

    Save as .min.js file or copy to clipboard. Ready for production deployment.

Common use cases for the JavaScript Minifier

Production deployment

  • Single-file scripts: Standalone JS embedded in HTML or served from CDN. Minify for smaller size.
  • WordPress plugins: Plugin JS files often not minified. Manually minify before deploy to users.
  • Static site scripts: Vanilla JS for static sites without build pipeline.
  • Third-party widgets: Embeddable scripts (chat widgets, analytics). Must be small.

Performance optimization

  • Reduce bundle size: Smaller JS bundle = faster Time to Interactive. Critical for mobile.
  • Improve Core Web Vitals: Smaller JS improves First Input Delay and Total Blocking Time.
  • CDN cost reduction: Bandwidth savings at scale — large apps can save thousands monthly.
  • Slow connection users: Users on 3G see dramatic improvement from smaller JS.

Special scenarios

  • Email tracking scripts: Embedded JS for email tracking — must be minimal.
  • Landing page trackers: GA, Facebook Pixel, etc. compete with user-facing JS for bandwidth.
  • Service Workers: SW scripts should be small for quick install.
  • Bookmarklets: Must fit in URL length limits (2000 chars).

Learning

  • Understand what minification does: See how your code transforms. Learn which patterns compress well.
  • Code obfuscation: Mangling provides light obfuscation — not security, but makes code harder to read.
  • Debug minified issues: When production bug appears, paste suspected minified code to analyze.

JavaScript Minifier — examples

Function minification

Mangled variable names.

Input
function calculateDiscount(price, discountRate) {
  const discount = price * discountRate;
  return price - discount;
}
Output
function calculateDiscount(a,b){return a-a*b}

Conditional simplification

Shortened with ternary.

Input
if (user.isAdmin === true) {
  showAdminPanel();
} else {
  showUserDashboard();
}
Output
user.isAdmin?showAdminPanel():showUserDashboard();

Dead code removal

Unreachable code stripped.

Input
const DEBUG = false;
if (DEBUG) {
  console.log("Debug info");
  debugger;
}
doRealWork();
Output
doRealWork();

Constant folding

Compile-time math.

Input
const SECONDS_IN_HOUR = 60 * 60;
const MS_IN_HOUR = SECONDS_IN_HOUR * 1000;
console.log(MS_IN_HOUR);
Output
console.log(3600000)

License preserved

Special comments kept.

Input
/*! MIT License 2026 */

function helper(x) {
  return x * 2;
}
Output
/*! MIT License 2026 */function helper(a){return 2*a}

Modern ES2015+ preserved

Modern syntax not downleveled.

Input
const users = [...oldUsers, ...newUsers];
const { name, age } = user;
const greeting = `Hello, ${name}!`;
Output
const users=[...oldUsers,...newUsers];const{name:a,age:b}=user;const c=`Hello, ${a}!`

Real-world savings

Typical React component file.

Input
5KB React component with comments, whitespace
Output
Minified: 1.8KB (64% smaller)
Gzipped: 0.8KB (84% total)

Technical details

JavaScript minification applies many optimizations. Typical result: 30-50% smaller than source.

Whitespace and comments:

- Remove all unnecessary whitespace.
- Remove comments (except /*! license */ style).
- Semicolons not always required — some minifiers use ASI (Automatic Semicolon Insertion).

Variable name mangling:

Rename local variables to short names:

```js
// Before
function calculateTotal(price, taxRate, discount) {
const withTax = price * (1 + taxRate);
const final = withTax - discount;
return final;
}

// After (mangled)
function calculateTotal(a,b,c){const d=a*(1+b);return d-c}
```

- Top-level names not mangled by default (preserved for external API).
- Properties mangled optionally (aggressive mode).
- Names kept short but unique per scope.

Dead code elimination:

```js
// Before
if (false) {
neverRuns();
}
const unused = 5;

// After
// (entire dead code block removed)
```

Constant folding:

```js
// Before
const ten = 10;
const result = 2 * 10 + 5;

// After
const a=25;
```

Function inlining:

Small functions may be inlined at call sites if only used once.

Conditional simplification:

```js
// Before
if (x === true) { foo(); } else { bar(); }

// After
x===true?foo():bar();
// Or even: x?foo():bar(); (if safe)
```

Property shorthand and destructuring (kept):

Modern syntax preserved — not converted back. Some older minifiers converted ES2015+ to ES5 but modern minifiers keep modern output.

What is preserved:

- Observable behavior identical to source.
- /*! */ license comments.
- Strings, regex, and template literals exact content.
- Object property names (unless aggressive mangling enabled).
- Function names (unless toplevel mangling enabled).

What changes:

- Variable names (mangled).
- Whitespace (removed).
- Comments (removed, except license).
- Unused code (removed).
- Expression ordering (optimized).

Build tool comparison (typical output size for same source):

- esbuild: very fast, basic minification.
- SWC: Rust-based, fast, comparable to esbuild.
- Terser: slower but best compression.
- Babel-minify: slower, good compression but less maintained.
- UglifyJS: legacy, ES5 only.

This tool uses Terser-compatible approach.

Source maps:

Production: serve minified JS. For debugging: include source maps (.map files) that browsers use to show original code in DevTools. This tool focuses on minification; generate source maps with build tools.

Performance optimizations:

Some minifiers include additional code optimizations:

- Loop unrolling for small loops.
- Hoisting declarations.
- Converting for-loops to forEach/map when shorter.

These are less common — focus is usually on size reduction without changing semantics.

Edge cases:

- eval(): minifier cannot fully analyze code inside eval. Typically preserves.
- with(): same issue — preserved.
- Object property access as dynamic: obj["name"] vs obj.name. Minifier may convert if static.
- JSX: expected to be compiled before minification. JSX source is not valid JS.
- TypeScript: compile to JS first, then minify.

Size comparison:

Typical React app:
- Source: 2MB (development bundle)
- Minified: 500KB (75% reduction)
- Gzipped: 150KB (92% total reduction)

The combined minification + gzip is the real production savings.

Common problems and solutions

Debugging minified code

Minified code is nearly unreadable. For production debugging, include source maps (.map files) that map minified back to source. This tool does not generate source maps — use build tools (Webpack, Vite, esbuild) for that.

Variable name dependencies

If your code depends on variable names (reflection, dynamic access with strings), mangling breaks it. Disable mangling for such code, or use identifier whitelist.

eval() behavior

Minifier cannot analyze code inside eval(). It preserves eval calls but the internal code is not minified. Avoid eval() in production for this and security reasons.

String references to variable names

If your code has strings like "userName" that reference variable names (reflection via strings), mangling breaks these. Use identifier whitelist or keep names unmangled.

Accidentally removing important code

Dead code elimination may remove code that looks unused but is needed (imported for side effects). Review output for missing functionality. Use /*@__PURE__*/ annotations to mark functions as pure.

Script-like code (template strings)

Code generated from template strings (eval-style) may not minify correctly. Refactor to proper functions.

Source and minified version mismatch

If you publish both minified and unminified versions, ensure they stay in sync. Minify at build time, not manually — easy to forget.

TypeScript not minified directly

Compile TypeScript to JS first (tsc), then minify. Or use esbuild/swc which do both in one step.

JavaScript Minifier — comparisons and alternatives

JavaScript Minifier vs Formatter: Minifier compresses for production. Formatter expands for readability. Opposite operations, lossless roundtrip (though formatter cannot restore original comments from minified).

Terser vs UglifyJS: Terser is the modern standard — supports ES2015+. UglifyJS is legacy, ES5 only. Most build tools use Terser.

esbuild vs Terser: esbuild is much faster (100x) but slightly less compression. Terser wins on size; esbuild wins on speed. Most modern build tools use esbuild for dev, Terser for production.

SWC vs Terser: SWC is Rust-based, fast like esbuild, good compression. Drop-in replacement for Terser in some projects (Next.js uses SWC).

Manual minification vs build tools: Build tools (Webpack, Vite, Rollup) minify automatically in production mode. This tool is for ad-hoc needs: single-file scripts, legacy code, standalone tools.

Minification vs Obfuscation: Minification reduces size. Obfuscation makes code deliberately hard to read (encrypted, control-flow flattened). Minification offers light obfuscation as a side effect; true obfuscation requires dedicated tools.

Code splitting + minification: Modern build tools split code into chunks for lazy loading. Minification + code splitting + gzip = optimal delivery.

Frequently asked questions about the JavaScript Minifier

What does JavaScript minification do?

Compresses JavaScript source by removing whitespace and comments, shortening variable names, and eliminating dead code. Typical result: 30-50% smaller. Minified code runs identically to source but transfers faster over the network.

How much can I save?

30-50% typical reduction from source. Heavy comments or whitespace save more. Already-minified or condensed code saves less. Combined with gzip compression, total HTTP reduction reaches 80-90%.

Is minification reversible?

Not fully. Whitespace and formatting can be restored with a formatter, but variable names are lost (mangled to short names). Source maps (generated during build) can restore original names for debugging, but source maps are separate files.

What is variable mangling?

Renaming variables to short names (a, b, c) to save bytes. Example: function calculate(userName, totalAmount) becomes function calculate(a,b). Behavior unchanged — just shorter.

When should I minify JS?

Always for production deploys. Never in development (hard to debug). Modern build tools (Webpack, Vite, esbuild) minify automatically in production mode. Use this tool for ad-hoc minification outside a build pipeline.

Is my code safe?

Yes. Minification happens in your browser. JavaScript never uploads. Safe for proprietary business logic, internal scripts, client work.

What about source maps?

Source maps (.map files) map minified code back to source for debugging in browser DevTools. This tool does not generate source maps — use build tools (Webpack, Vite, Rollup with sourcemap options).

Can I minify TypeScript?

Compile first, then minify. Run tsc to compile .ts to .js, then minify the .js. Or use esbuild/swc which do both in one step. This tool expects plain JavaScript.

Does minification obfuscate my code?

Partially. Variable mangling makes code harder to read. But structure, logic, and strings remain visible. Not real obfuscation — attacker can still reverse-engineer logic. For true obfuscation, use dedicated tools (obfuscator.io).

What about ES2015+ features?

Modern minifiers preserve modern syntax (arrow functions, classes, async/await, spread operator). They do not compile to ES5 (that is a separate transpilation step via Babel or SWC). If your target environment supports modern JS, do not transpile — minify only.

Additional resources

  • TerserModern JavaScript minifier (ES2015+). Used by most build tools.
  • esbuildExtremely fast JS bundler with minification.
  • SWCRust-based JS compiler with minification.
  • Webpack optimizationHow Webpack minifies in production.
  • Source MapsDebugging minified code in production.
Advertisement

Related tools

All Minifiers

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →