JavaScript Minifier
Compress and minify JavaScript using Terser — with variable mangling, dead-code removal, and size stats.
Last updated: March 25, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is JavaScript Minifier?
JavaScript minification is the most impactful single optimization for web performance. Unlike images (which require quality trade-offs) or HTML (small gains), JavaScript minification routinely reduces file sizes by 30–70% with zero functional change. It works by removing whitespace and comments, shortening local variable and function names to single letters (mangling), removing dead code branches, and simplifying constant expressions — entirely automatically.
This tool uses Terser, the industry-standard JavaScript minifier used internally by Vite, Webpack, Rollup, Parcel, and esbuild. It supports modern JavaScript syntax including ES2022 (class fields, top-level await), JSX-free TypeScript syntax, and ECMAScript modules. Unlike older tools like UglifyJS (ES5 only), Terser handles arrow functions, destructuring, optional chaining, and all modern JavaScript patterns correctly.
How to Use JavaScript Minifier
Paste your JavaScript code into the input area on the left
Select a compression level: Safe (whitespace + comments only), Standard (+ mangling), Aggressive (+ dead code removal)
Click "Minify" to run Terser and see the compressed output
Review the compression stats: original size, minified size, and percentage saved
Click "Copy" to copy the minified JS, or "Download .js" to save it as a file
Common Use Cases
- Compressing vanilla JavaScript files before serving from a CDN or static host
- Reducing the size of third-party library customizations or patches
- Minifying standalone scripts (analytics snippets, embed widgets) before distribution
- Quick benchmarking of how much JS size a specific code pattern adds
- Compressing a polyfill file before including it in a legacy support bundle
- Minifying utility scripts embedded in WordPress themes or plugins
- Reducing the size of JavaScript served in a <script> tag inline in HTML
- Validating that a specific Terser configuration produces the expected output
Example Input and Output
A readable utility function minified to a single optimized line:
/**
* Formats a number with thousands separators
* @param {number} num - The number to format
* @returns {string} Formatted number string
*/
function formatNumber(num) {
if (typeof num !== 'number' || isNaN(num)) {
return '0';
}
return num.toLocaleString('en-US');
}function formatNumber(n){return"number"!=typeof n||isNaN(n)?"0":n.toLocaleString("en-US")}Privacy First
All JavaScript minification runs in your browser using Terser (compiled to WebAssembly). Your source code — including any API keys, business logic, or internal algorithms — is never transmitted to our servers.
Use Source Maps in Production
When using minified JavaScript in production, always generate source maps alongside it. Source maps let browser DevTools show original, readable code when debugging errors — while serving the minified file to end users. Build tools like Vite generate source maps automatically.
ES Module Compatibility
This tool supports modern ESM syntax (import/export, dynamic import()). However, it does not bundle modules — it minifies a single file. If your code uses ES module imports, bundle with esbuild or Rollup first, then optionally run through Terser for final compression.
Frequently Asked Questions
What is the difference between minification and obfuscation?
What does "mangling" mean in JavaScript minification?
Will minification break my JavaScript?
How much size reduction should I expect?
Should I minify JavaScript manually or use a build tool?
What is dead code elimination?
How This Tool Works
The JavaScript source is passed to Terser running as a WebAssembly module in the browser. Terser performs a multi-pass compression pipeline: (1) parse the JS into an AST (Abstract Syntax Tree), (2) compress: fold constants, remove dead code, simplify boolean expressions, inline single-use variables, (3) mangle: rename local identifiers, (4) generate: serialize the optimized AST to a compact string without non-essential whitespace. All passes run synchronously in-browser with no network calls.
Technical Stack