Minify JavaScript to shrink file size for production using Terser — the same minifier used by major bundlers. See original size, minified size, and exact savings, all computed in your browser.
JavaScript is frequently the largest asset type on a modern web page, and unlike CSS, it isn't just downloaded — the browser also has to parse and compile it before any of it can run, and in many cases execute it before the page becomes interactive. Every byte removed from a JavaScript bundle reduces all three of these costs: download time, parse and compile time, and often first-load execution time, making minification one of the highest-leverage, lowest-effort performance optimizations available for any JavaScript-heavy site or application.
Beyond raw whitespace and comment removal, a proper minifier like Terser performs genuine code transformations that a human wouldn't reasonably apply by hand across an entire codebase: eliminating unreachable code, shortening variable names throughout every scope, simplifying boolean and arithmetic expressions, and inlining variables that are only referenced once. On a real production bundle, these combined optimizations routinely cut file size by 30-70% depending on how verbosely the original source was written, which translates directly into faster page loads — especially significant for users on slower connections or lower-powered devices, where JavaScript parse and execution time can dominate total load time even more than the download itself.
A real JavaScript minifier doesn't operate on raw text — it fully parses your source code into an Abstract Syntax Tree (AST), the same structured, hierarchical representation of your program's actual logic that a JavaScript engine itself builds before executing your code. Working from this AST rather than from text is what makes safe, aggressive minification possible: the minifier can prove that a particular variable is only ever referenced within a specific scope, or that a branch can never be reached given a constant condition, in a way that a naive text-based find-and-replace tool never could.
From this parsed representation, Terser applies its transformations in stages: a compression pass that simplifies and shortens equivalent code (removing dead branches, folding constant expressions, collapsing sequential statements), a mangling pass that renames every local variable and function parameter to the shortest available identifier while carefully preserving anything that must keep its original name (globals, exported names, property keys accessed dynamically), and finally a code-generation pass that serializes the optimized AST back into JavaScript text using the most compact valid syntax — omitting unnecessary semicolons, parentheses, and whitespace wherever the grammar allows it.
These three build steps are often applied together in a modern JavaScript build pipeline but each solves a genuinely distinct problem, and it's worth understanding the difference. Bundling (done by tools like Webpack, Rollup, or esbuild) combines many separate source files and their dependencies into one or a few output files, reducing the number of separate network requests a browser needs to make to load your application. Transpilation (done by Babel or a similar tool) rewrites modern JavaScript syntax into an older, more widely-supported syntax so your code runs correctly on browsers that don't yet support newer language features — this is a correctness and compatibility concern, not a size concern.
Minification, the step this tool performs, comes after bundling and transpilation in a typical pipeline and focuses purely on making the final, already-combined, already-compatible code as small as possible without changing its behavior. A production build pipeline typically runs all three in sequence — transpile for compatibility, bundle for fewer requests, then minify for smaller size — and it's worth minifying last, since minifying before bundling or transpiling can interfere with those later steps' ability to analyze and transform your code correctly.
Always keep your original, readable, well-commented source code as the single source of truth in version control, and treat minified output as a disposable, regenerable build artifact — never hand-edit minified code directly, since any change would be silently lost the next time your build pipeline regenerates it from source. In a real project, minification should be an automated part of your production build step, paired with source map generation, so that error monitoring tools and browser DevTools can map a minified stack trace back to the original, readable source line when something goes wrong in production — without source maps, debugging a live issue in minified code becomes dramatically harder.
Double-check any code that relies on a function or class's .name property, or on Function.prototype.toString() output, for actual runtime logic (rather than pure debugging/logging) before minifying it, since mangling is specifically designed to change those names and can break logic that secretly depends on them. Finally, remember that minification and compression (gzip or Brotli, applied by your web server) are complementary, not redundant — minification reduces the raw byte count before compression even runs, and compression then squeezes further redundancy out of the minified result, so a production deployment benefits from doing both rather than treating either as sufficient on its own.
JS Minifier optimizes script size for production. These related developer tools cover other performance and formatting tasks in the same front-end build workflow.