JavaScript Minifier and Compressor Online
Use this online JavaScript minifier to quickly minify, compress, and optimize your JS for production. Type, paste or upload files, choose the target ECMAScript version, and pick the parse, compress, and format options that match your build. The tool reduces payload while preserving runtime behavior and core functionality.
Core Features
- Minify to remove comments, whitespace, and redundant tokens
- Compress using advanced passes that drop dead code and remove unused items
- Mangle names to shorten variables and properties for maximum savings
- Choose Enclose to wrap output in a top level closure for safer bundles
- Parse options include bare returns, HTML5 comments, and shebang support
- Fine grain compress options such as collapse vars, evaluate, and many more
- Control console and debugger removal easily in compress options
- Runs fully in the browser so no server upload is required
How to use this online JS compressor
- Write, paste or upload your JavaScript into the editor
- Choose customization options as per you requirement
- Click Minify JavaScript button
- Preview the result, and download it
Why use a JavaScript minifier or optimizer
Smaller scripts mean faster downloads and better time to interactive. A minifier tool shrinks files by removing whitespace and comments and by shortening names.
A compressor goes further by evaluating constants, removing unreachable code, and merging statements. Use the JS minifier tool to reduce bandwidth and speed up page load, while keeping the original source in version control for development and debugging.
Balance size and traceability by tuning mangle and keep name settings. If you need clear stack traces, enable keep function names option. If you want maximum size reduction, allow mangling and enable compress inlines and dead code removal.
Key differences: original JS vs minified JS
- Original JS is readable and easy to debug with full identifiers and comments
- Minified JS removes comments and whitespace and shortens identifiers to save bytes
- Compressed JS may also evaluate constants, inline small functions, remove unused code, and change statement order to reduce size
Example 1: Simple function
Original JS
function square(x) { // return square of x return x * x; } console.log(square(5));
Minified JS
function square(e){return e*e}console.log(square(5));
Example 2: Modern features and classes
Original JS
function formatString(e, ...t) { return e.replace(/{(d+)}/g, (e, n) => void 0 !== t[n] ? t[n] : e) } function validateEmail(e) { return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/.test(e) } function debounce(t, n) { let u; return (...e) => { clearTimeout(u), u = setTimeout(() => t(...e), n) } } function throttle(t, n) { let u = !1; return (...e) => { u || (t(...e), u = !0, setTimeout(() => u = !1, n)) } } const a = formatString("Hello, {0}!", "World"); console.log(a); const b = validateEmail("example@example.com"); console.log(b); const debouncedLog = debounce(console.log, 500); debouncedLog("Debounced"); const throttledLog = throttle(console.log, 500); throttledLog("Throttled");
Minified JS (ES6 target, mangle enabled)
function formatString(o,...e){return o.replace(/{(d+)}/g,((o,t)=>void 0!==e[t]?e[t]:o))}function validateEmail(o){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/.test(o)}function debounce(o,e){let t;return(...n)=>{clearTimeout(t),t=setTimeout((()=>o(...n)),e)}}function throttle(o,e){let t=!1;return(...n)=>{t||(o(...n),t=!0,setTimeout((()=>t=!1),e))}}const a=formatString("Hello, {0}!","World");console.log(a);const b=validateEmail("example@example.com");console.log(b);const debouncedLog=debounce(console.log,500);debouncedLog("Debounced");const throttledLog=throttle(console.log,500);throttledLog("Throttled");
Example 3: Advanced bundle with dead code removal
Original JS
const DEBUG = false; function calc(a, b) { if (DEBUG) { console.log("debug mode"); } return a + b; } function unused() { return "this will be removed"; } export default function main() { console.log(calc(10, 20)); }
Minified JS (dead code dropped)
function calc(n,t){return n+t}console.log(calc(10,20));
Customization Options
Below are are all the JS optimization options available while cmopressing JavaScript.
Option | Default | Description |
---|---|---|
ECMAScript Version | ES5 (2009) | Target language level for output compatibility |
Enclose | False | Wrap output in a top-level function closure |
Mangle Names | True | Shorten variable and property names to save bytes |
Keep Classnames | False | Preserve class names when mangling identifiers |
Keep Function Names | False | Preserve function names for clearer stack traces |
Bare Returns | True | Allow return statements outside functions in parsing |
HTML5 Comments | True | Preserve HTML5-style comments when parsing |
Shebang | True | Support parsing of shebang lines (#!) in scripts |
Arrow Optimization | True | Convert functions to arrow syntax where safe |
Collapse Vars | True | Merge single-use variable definitions to reduce code |
Reduce Vars | True | Optimize repeated variable references by reusing values |
Join Vars | True | Combine consecutive variable declarations into a single statement |
Passes | 1 | Number of times compress optimizations are applied |
Comparisons | True | Simplify comparison expressions for smaller output |
Unsafe Comparisons | False | Allow potentially unsafe optimizations on comparisons |
Conditionals | True | Transform conditional statements for compactness |
Dead Code Removal | True | Strip unreachable code blocks from the bundle |
Unused Removal | True | Remove unused variables and functions |
Directives | True | Apply directives like "use strict" where possible |
Drop Console | False | Remove console statements from the code |
Drop Debugger | True | Remove debugger statements from the code |
Evaluate | True | Compute constant expressions at build time |
Hoist Properties | True | Move static object properties to reduce repeated lookups |
Top-level Optimization | False | Optimize variables and functions declared in the top scope |
Preserve Infinity | True | Keep literal Infinity instead of replacing with 1/0 |
If Return | True | Optimize if statements followed by return for compactness |
Inline | True | Inline functions where beneficial |
Reduce Functions | True | Optimize repeated function expressions |
Sequences | True | Use sequence expressions to merge statements |
Side Effects | True | Drop expressions without side effects |
Switch Optimizations | True | Optimize switch statements for smaller code |
Typeof Optimizations | True | Optimize typeof expressions when safe |
ASCII Only | False | Escape non-ASCII characters in output |
Beautify | False | Format output code for readability instead of minifying |
Always Braces | False | Force curly braces on blocks for consistent style |
Preserve Comments | False | Keep selected comments such as licensing or banner text |
Banner Comment | Empty | Text to prepend to the optimized file for identification |
Best practices
- Keep original code in version control
- Minify for production only; keep readable builds for development
- Generate source maps for easier debugging, though not included in this JS minifier
- Test minified output across browsers and devices
- Review third-party libraries before heavy optimization
- Automate minification in CI with environment flags
- Use multiple passes only when necessary
Conclusion
This JavaScript minifier and compressor helps you shrink bundles and improve load time and runtime performance. Choose ECMAScript version and refine parse, compress, and format options to match your environment. Test the final output across devices and browsers before deploying to production.