Free Developer Tool

JavaScript Minifier

Remove whitespace, comments, and shorten variable names to shrink JS file sizes. Powered by Terser - the same engine used in Webpack and Vite.

[ Advertisement - 728x90 Leaderboard ]

Minification Engine Powered by Terser v5

100% browser-side - your code never leaves your device
Compiler Options
Original Size
-
KB
Minified Size
-
KB
Total Savings
-%
Characters Removed
-
Syntax Error: Check your code for missing brackets or typos.
Minification complete! Your code has been compressed successfully.
input.js
Raw JS
output.min.js
Minified
Copied!

The Ultimate Guide to JavaScript Minification and Performance

Everything developers need to know about shrinking JS file sizes, from beginner concepts to production-grade techniques.

Every byte you ship to a user's browser has a cost: bandwidth, parse time, and execution delay. For JavaScript files, this cost is amplified because the browser must not only download the file but also parse it into an Abstract Syntax Tree (AST) - a structured, tree-based representation of every variable, function, and operation in your code. The browser's JavaScript engine walks this tree to compile and run your program. Larger files mean more nodes in the tree, slower parse times, and a worse experience for users on mobile data or slower devices. Minification is the engineering discipline of reducing file size without altering that tree's behavior - the output runs identically to the original.

Modern bundlers like Webpack, Vite, and Parcel all run Terser internally as their default minification pass. When you use this tool, you are running the exact same production-grade engine directly in your browser, with zero server round-trips. It is not a fragile find-and-replace script. Terser fully parses your code into an AST, applies transformations at the node level, and then re-serializes the result into compact form. This means it handles edge cases like string literals containing whitespace, regular expressions with comment-like patterns, and template literals correctly - situations that break simple regex-based approaches.

These two terms are commonly confused, but they serve different engineering goals.

Minification is a mechanical process with a single purpose: reduce file size. It removes whitespace, newlines, and comments, and can rename internal variables to shorter names. The resulting code is harder for humans to read but is still completely decompilable by any experienced developer using browser DevTools. Minification does not protect your intellectual property. It only makes your code smaller.

Obfuscation, by contrast, is an intentional attempt to make code difficult to reverse-engineer. An obfuscator might encrypt string literals, wrap logic in self-executing functions, introduce bogus dead code paths, or encode variable names as hexadecimal sequences. The goal is to maximize confusion for a human reader, not to minimize bytes for a network transfer. Obfuscated code is often larger than the original.

For most web applications, minification is sufficient and appropriate. Obfuscation is primarily used in licensing-sensitive software, anti-cheat systems in browser games, or DRM implementations. For everyday production JS, rely on minification and keep your proprietary server-side logic off the client entirely.

Variable Mangling is the process of replacing long, descriptive internal variable and function names with the shortest possible alternatives - typically single letters like a, b, or c. The key word is "internal": mangling only touches names that are scoped inside functions and are not part of the public API. Global names and object property keys that other scripts depend on are left untouched by default.

The savings compound quickly in real codebases. Consider a 1,000-line application where the variable userAuthenticationToken appears 30 times. That variable name alone consumes 30 x 23 = 690 bytes. After mangling, it becomes a, saving 660 bytes from a single variable. Multiply this across hundreds of variables and function parameters, and mangling routinely delivers 10-25% additional compression on top of whitespace removal alone.

Terser's mangling algorithm is scope-aware. It builds a complete map of all variable declarations and references before renaming anything, ensuring no two variables in the same scope receive the same short name and that no references are accidentally broken.

console.log() calls left in production JavaScript are more than just clutter - they are an active security and performance risk. Every log statement evaluates its arguments and writes to the browser's DevTools console even when no developer has the DevTools panel open. This means three concrete problems arise:

1. Information Disclosure: Developers often log internal data structures, API response payloads, authentication tokens, or user objects during debugging. If these logs remain in the production bundle, any end-user who opens DevTools can read this sensitive internal state. This is a real-world security vulnerability, not a theoretical one.

2. Performance Cost: Each console.log() call has a measurable runtime cost. In tight loops or event handlers that fire frequently (like scroll or mousemove listeners), logging adds perceptible latency that degrades user experience.

3. Professional Quality Signal: Visible console output in a production application is a reliable signal to technical users and security auditors that the codebase lacks a proper build pipeline. It erodes trust in the product's engineering quality.

The "Strip console.log() statements" option in this tool uses Terser's drop_console option to remove these calls at the AST level during the minification pass, so you never need to manually hunt and delete them before shipping.

With a proper AST-based minifier like Terser, minification should never break syntactically valid JavaScript. Terser's transformations are semantics-preserving by design: the output executes identically to the input for all valid inputs. However, there are two categories of problems to be aware of:

Existing Bugs Surface: Minification collapses code that implicitly depended on quirks like automatic semicolon insertion (ASI) or undefined behavior. If your code had a latent bug that happened to work in development, minification may expose it. The fix is always in your original source code, not in the minifier.

Variable Mangling with Eval: If your code uses eval() to dynamically reference variable names by string (e.g., eval('myVar')), mangling will break those references because the variable name is now a instead of myVar. Terser can detect and handle most of these cases, but eval() usage is strongly discouraged in modern JavaScript for both security and performance reasons. The solution is to refactor away from eval().

Dead Code Elimination - a related optimization where Terser removes code it can prove will never execute (e.g., code after an unconditional return statement, or branches of an if (false) { ... } block) - is always safe and correct by definition. Dead code cannot affect runtime behavior because it never runs.

Render-Blocking describes any resource that forces the browser to pause building the visual page (the render tree) until the resource is fully downloaded and processed. By default, a <script> tag in an HTML document is render-blocking: when the browser's HTML parser encounters it, parsing stops completely, the script file is fetched, and JavaScript runs before the browser renders a single pixel of content below that point.

This is why Google's Core Web Vitals score (which directly influences search rankings) penalizes large JavaScript files. A 500 KB unminified JS file on a 3G mobile connection might take 4-5 seconds to download and parse, holding the page blank the entire time. The same file minified to 180 KB loads in under 2 seconds and delivers a dramatically better First Contentful Paint (FCP) and Largest Contentful Paint (LCP) score.

Minification is the first and most impactful step in a performance optimization pipeline. Subsequent steps - HTTP/2 multiplexing, Brotli/gzip compression, code splitting, and the defer or async attributes on script tags - stack on top of a minified baseline. Start here, then layer additional optimizations based on your specific performance budget.

Before and After: Real-World Example

The same function, before minification (with comments and descriptive names) and after (compressed to a single line with mangled variables).

before.js 389 bytes
// Calculate the total price including tax // and apply a discount code if provided. function calculateOrderTotal( itemPrice, taxRate, discountCode ) { var subtotal = itemPrice; var taxAmount = itemPrice * taxRate; var discountAmount = 0; if (discountCode === "SAVE10") { discountAmount = subtotal * 0.10; } return subtotal + taxAmount - discountAmount; }
after.min.js 99 bytes
function calculateOrderTotal(a,b,c){let d=0;if(c==="SAVE10")d=a*.1;return a+a*b-d}
75%
Smaller file. Same behavior. From 389 bytes down to 99 bytes - comments stripped, whitespace removed, variables mangled. The function executes identically in both forms.
🔒

Privacy First: Your Code Stays On Your Device

This tool runs entirely within your local web browser using client-side JavaScript. Your proprietary source code and application logic are never uploaded, saved, or sent to any external server. The minification engine (Terser) is loaded once from a public CDN and then executes locally. Close the browser tab and nothing persists.