Loading…

About Online JavaScript Minifier

Ship smaller JavaScript bundles in seconds ⚡. This online JavaScript Minifier parses your JS into an AST, strips comments and unnecessary whitespace, and applies safe compression passes. Ideal for shrinking standalone scripts, quick fixes, tag manager snippets, and pre-deploy checks. Everything runs 100% client-side – your code never leaves the browser.

Key Features of This JavaScript Minifier

  • Instant, in-browser JS compression (no file uploads to servers)
  • Removes comments and collapses unnecessary whitespace/newlines
  • AST-based compression similar to Terser (constant folding, dead-code removal under safe conditions)
  • Optional identifier mangling and advanced flags via API or build integration
  • Works with modern JavaScript (ES2015+), classic scripts and simple module output
  • One-click copy or download of the minified JavaScript
  • Uses the same core component as the JavaScript formatter: switch between formatted and minified output with one action
  • 100% client-side processing for maximum privacy

🛠️ How to Minify JavaScript for javascript-minifier

1

Paste or Upload Your JS

Drop a .js/.mjs file into the editor or paste your JavaScript directly. The tool is ideal for single scripts, utility files, and small bundles.

2

Choose Minification Mode

Use the same component as the JavaScript formatter: switch to the Minify action to get compressed output instead of formatted code.

3

Run the Minifier

Your code is parsed into an AST, comments and extra whitespace are stripped, and safe compression passes are applied to reduce bundle size.

4

Copy or Download the Result

Copy the minified JavaScript from the output editor or download it as a .min.js file and include it in your HTML, CDN or build output.

Technical Specifications

Core Transformations (Safe Defaults)

Conservative defaults are designed to preserve runtime behavior while significantly shrinking code size.

OperationAppliedNotes
Remove line and block commentsLicense comments (/*! ... */) can be preserved via configuration/API
Collapse whitespace and newlinesWhitespace normalized where semantically safe; string and regex contents preserved
Constant folding and simple inliningOnly when the result is provably equivalent
Dead-code eliminationRemoves branches that are unreachable after constant propagation
Identifier mangling✅ OptionalShortens variable and function names; configurable via advanced options/API
Drop debugging helpers (console/debugger)✅ OptionalCan be enabled when you do not rely on console output in production

Safety & Compatibility Controls

Advanced options (exposed mainly via build tools/API) help tune how aggressive minification should be.

OptionDefaultExplanation
ecma target2020Controls output syntax and some compress rules
module vs scriptscriptEnable module/toplevel optimizations for ESM bundles
keep_fnames / keep_classnamesfalsePreserve names for better stack traces or DI frameworks
safari10 / legacy quirksoffEnable only when targeting specific legacy engines
toplevelfalseAllows dropping unused top-level bindings for advanced tree-shaking

Typical Size Reduction

Savings vary depending on original formatting, comment density, and how much dead code exists.

Input StyleCompress OnlyCompress + Mangle (Aggressive)
Heavily commented and spaced35%–55%50%–70%
Moderately formatted application code20%–35%35%–55%
Already compact code5%–15%10%–25%

CLI Alternatives for Production Builds

For full applications and multi-file projects, integrate minification into your CI/CD pipeline.

Node.js

Terser (common case)

npx terser src/app.js -o dist/app.min.js -c ecma=2020,passes=2 -m

Two compress passes plus identifier mangling for strong size reduction.

Terser with reserved names and drop_console

npx terser src/app.js -o dist/app.min.js -c passes=2,drop_console=true -m reserved=["React","ReactDOM"] --keep-fnames

Protect important globals, remove console calls, and keep function names for debugging.

Linux/macOS/Windows

esbuild (very fast)

npx esbuild src/app.js --minify --target=es2018 --outfile=dist/app.min.js

Bundle and minify in a single, extremely fast step.

SWC (Rust-based)

npx swc src -d dist --minify

Transpile and minify with a high-performance Rust engine.

Common Use Cases

Web Performance & Core Web Vitals

  • Reduce JavaScript transfer size for faster LCP and TTI
  • Trim debug comments and logging before deployment
  • Shrink client-side bundles before gzip/brotli compression
/* build-only comment that will be stripped in minified output */

CI/CD and Release Automation

  • Minify JS as a final step in your build pipeline
  • Prepare small, cache-friendly bundles for CDNs
  • Generate production-ready assets alongside HTML/CSS minifiers

Widgets, Embeds & Experiments

  • Ship compact snippets via tag managers
  • Embed minified widgets in third-party pages
  • Experiment with different compress strategies on critical scripts

❓ Frequently Asked Questions

Will minifying JavaScript change how my code runs?

With safe defaults, runtime behavior should remain identical. Aggressive options such as toplevel optimizations, identifier mangling, or dropping console calls can affect behavior if your code relies on names, side-effects, or logging. Always keep an unminified version and run tests on minified builds.

Does this tool handle TypeScript or JSX directly?

The minifier targets plain JavaScript. For TypeScript or JSX, first transpile to JavaScript (via SWC, esbuild or Babel) and then minify the generated JS code.

Is my JavaScript uploaded to a server?

No. All processing happens entirely in your browser using client-side code. Source code is not sent to any remote server, which is ideal for private/proprietary scripts.

How big can my JavaScript file be?

For smooth browser UX, we recommend files up to roughly 1 MB in this online tool. Larger bundles and repeated minification runs are better handled by CLI tools integrated into your build pipeline.

What is the difference between formatting and minifying?

Formatting makes code more readable (consistent indentation and spacing). Minifying makes code smaller (removing whitespace, comments and redundant code). This tool shares the same core component for both: use the Format action for readability and the Minify action for production bundles.

Pro Tips

Best Practice

Define NODE_ENV=production (or equivalent) in your bundler to unlock additional dead-code pruning in many libraries.

Best Practice

Keep unminified sources (and, for large apps, source maps) in version control, and serve only minified assets in production.

Best Practice

Use reserved names when mangling to protect public APIs hanging off window or globalThis.

Performance Tip

Combine minification with gzip or brotli at the CDN or server level to get multiplicative size savings.

Additional Resources

Other Tools