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")}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
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?
Minification removes whitespace and shortens names to reduce file size — the logic remains readable if reformatted. Obfuscation intentionally transforms code to make it very hard to understand (renaming to nonsense, encoding strings, adding junk code). Minification is for performance; obfuscation is for (imperfect) code protection. This tool performs minification + optional mangling, not full obfuscation.
What does "mangling" mean in JavaScript minification?
Mangling renames local variables, function parameters, and class fields from descriptive names to single characters (firstName → a, calculateTotal → b). This significantly reduces file size. Mangling is safe for local scope names because they are only used within the function. Global names (window.myFunction, module.exports) are never mangled since external code depends on them.
Will minification break my JavaScript?
Not for correctly written JavaScript. Known edge cases: (1) code that reads function.name or variable.name for reflection, (2) code that uses arguments.callee (deprecated strict mode violation), (3) eval() with string code that references local variable names (extremely rare). These patterns are already considered bad practice and should not appear in modern code.
How much size reduction should I expect?
20–50% for typical application JavaScript with standard settings. 50–70% for heavily commented utility libraries. Files that are already minified will see minimal improvement. The largest gains come from removing comments, mangling long variable names, and collapsing small functions.
Should I minify JavaScript manually or use a build tool?
For production applications, always use an automated build tool (Vite, Webpack, Parcel, esbuild) that minifies as part of the build pipeline. This tool is best for: WordPress/theme scripts without a build step, standalone utility scripts, CDN-hosted custom code, and quick checks to verify minification output.
What is dead code elimination?
Dead code is code that can never execute — for example, code after a return statement, or an if (false) block, or a function that is never called. Terser identifies and removes dead code branches during the "compress" pass. This is separate from tree-shaking (which is module-level dead code removal performed by bundlers at the import level).
Related Tools
JavaScript Beautifier
Format and beautify minified or messy JavaScript code.
HTML Minifier
Compress HTML by removing whitespace, comments, and redundant attributes — with size reduction stats.
CSS Minifier
Compress and minify CSS code to reduce file size and speed up page loads.
JSON Formatter
Format, validate, and beautify JSON instantly — with clear error messages, Tree View, Diff mode, and Schema validation.
Regex Visualizer
Visualize regular expressions as interactive railroad diagrams — understand complex patterns with a clear SVG flowchart, live match testing, and flag explanations.
Lua Minifier
Minify Lua source code by removing comments and collapsing whitespace — reduces file size for embedding in games, configs, or deployments.

