JavaScript Minifier
Remove comments, console.log calls, and whitespace to reduce JS file size — all in your browser, nothing sent to any server
Minified JavaScript will appear here.
Minification Options
Your bundle analyzer shows 40KB of console.log() calls, debug comments, and debugger statements in your production JavaScript. Your build pipeline uses Terser for variable renaming and dead code elimination, but right now you need to minify a standalone script that isn’t part of the build — a third-party widget, a bookmarklet, or a quick snippet for a Stack Overflow answer.
Why This Tool (Not Terser in Your Build Pipeline)
Terser and esbuild are the right choice for production builds with tree shaking and mangling. This tool is for quick one-off minification — paste JavaScript, strip comments, remove console.log calls and debugger statements, collapse whitespace, and copy the result. Perfect for scripts outside your build system or testing what your build should output. Everything runs in your browser; no data is sent anywhere.
What Is a JavaScript Minifier?
A JavaScript minifier reduces the file size of JavaScript code by removing everything that is not required for the code to execute correctly:
- Whitespace: Spaces, tabs, and newline characters that exist only for human readability
- Comments: Single-line (
// ...) and block (/* ... */) comments that explain the code but are irrelevant at runtime - Redundant characters: Spaces around operators, after keywords, and between tokens that the JavaScript engine does not need
The resulting code is functionally identical to the original — it runs the same way in every JavaScript engine — but occupies significantly less space. For websites and web applications, smaller JavaScript means faster downloads, faster parsing, and faster execution.
How Much Can JavaScript Minification Save?
Savings depend on how verbosely the source is written:
| Source type | Typical Savings |
|---|---|
| Heavily commented utility library | 30–60% |
| Standard application code | 15–35% |
| Already minified or dense code | 0–10% |
| Code with many console.log calls | +5–15% from console removal |
Modern bundlers like Webpack, Vite, and Rollup apply minification automatically in production builds using tools like Terser or esbuild. This online tool is useful for one-off minification, quick size checks, or when you cannot use a build tool.
Minification Options
Remove Comments
Strips all single-line (// ...) and block (/* ... */) comments from the code. Comments are helpful during development but add bytes to production bundles without affecting behavior.
Preserved comments: Comments containing @license or @preserve are kept even when this option is enabled. These comments typically contain copyright notices and license information that must be distributed with the code.
Remove console.log
Removes console.log(), console.warn(), console.error(), console.info(), console.debug(), and related console method calls from the code. Developers often add logging statements during debugging that should not appear in production. Removing them reduces code size and avoids exposing internal state to end users.
This option correctly handles console calls with complex arguments, including string literals, template literals, and nested function calls.
Remove debugger
Removes debugger; statements. The debugger keyword pauses JavaScript execution in a browser debugger. These statements are always a mistake in production code — they cause performance issues and expose your code to scrutiny. This option removes all debugger statements automatically.
How Whitespace Collapsing Works
The minifier collapses whitespace while preserving the semantics of the code:
- All newlines, tabs, and multiple spaces are normalized to a single space
- Spaces between two identifier characters (letters, digits,
$,_) are preserved to prevent token merging — for example,return valuecannot becomereturnvalue - Spaces adjacent to punctuation characters (
;,{,},(,), etc.) are removed - Leading and trailing whitespace is removed from the output
String literals, template literals, and regular expression literals are never modified — their contents are passed through unchanged, including any whitespace or special characters inside them.
How to Use the JavaScript Minifier
- Paste your JavaScript into the left input panel
- The minifier runs automatically and displays the minified output on the right
- The stats bar shows the original size, minified size, and percentage saved
- Toggle options to include or exclude specific transformations
- Click Copy to copy the minified code to your clipboard
The minification runs entirely in your browser — your JavaScript code is never transmitted to any server.
JavaScript Minification and Web Performance
JavaScript is often the primary bottleneck in web page load performance. Minification helps in several ways:
Network transfer: Smaller JavaScript files download faster, especially on slow mobile connections. Combined with gzip or Brotli compression, minified JavaScript can be 60–80% smaller than the original.
Parse time: JavaScript engines must parse the source text before executing it. Smaller files parse faster, reducing Time to Interactive (TTI) and improving Interaction to Next Paint (INP).
Caching efficiency: Minified files change less frequently in structure, making cache invalidation more predictable.
For pages serving JavaScript to users on mobile networks or older devices, every kilobyte saved translates directly into faster page loads and better Core Web Vitals scores.
Minification vs Bundling vs Tree Shaking
These three techniques are often used together but serve different purposes:
| Technique | What it does | Tools |
|---|---|---|
| Minification | Removes whitespace, comments, and shortens code | Terser, esbuild, this tool |
| Bundling | Combines multiple JS modules into fewer files | Webpack, Vite, Rollup, esbuild |
| Tree shaking | Removes unused exports and dead code | Rollup, Webpack, esbuild |
For production deployments, all three are typically applied together using a build tool. This online minifier handles the minification step for cases where a full build pipeline is not available or not needed.
Minification vs Obfuscation
Minification and obfuscation are different:
- Minification shortens code by removing redundant characters. The structure and logic are preserved; identifiers keep their original names. Minified code can be made readable again with a code formatter.
- Obfuscation intentionally transforms code to make it difficult to understand: renaming variables to meaningless names, encoding strings, inserting junk code. Obfuscated code is harder to reverse-engineer but also harder to debug and can affect performance.
This tool performs minification only, not obfuscation. The “Mangle identifiers” option renames local variables to shorter names (an optimization borrowed from obfuscation), but the structural logic of the code remains the same.
Common Questions
Is my JavaScript code sent to a server? No. All minification runs entirely in your browser using JavaScript. Your code is never transmitted to any server and never leaves your device.
Can I undo the minification? Minification is not directly reversible, but you can use a JavaScript formatter or beautifier to add whitespace back and make the code readable. Comments and original variable names (unless mangled) are lost permanently. Always keep a copy of the original source before minifying.
Does minification break my code? In almost all cases, no. The minifier is conservative: it only removes whitespace and optionally comments, console calls, and debugger statements. String and regex literals are never modified. If you encounter an issue, try disabling individual options to isolate the cause.
What about source maps? Source maps link minified code back to the original source, enabling debugging in production. This tool does not generate source maps. For production use with source maps, use Terser or esbuild in your build pipeline.
Why is my minified code larger than expected? If your code is already dense or uses short variable names, there is little whitespace to remove. The biggest savings come from heavily commented code or code with verbose formatting.
What is Terser? Terser is the standard JavaScript minifier used by most build tools (Webpack, Vite, Rollup, Parcel). It performs advanced optimizations including full scope-aware variable renaming, dead code elimination, and expression simplification. This tool implements a safe subset of Terser’s whitespace removal that runs directly in the browser without installation.