JavaScript Minifier & 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 minifier

  1. Write, paste or upload your JavaScript into the editor
  2. Choose customization options as per you requirement
  3. Click Minify JavaScript button
  4. 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

Copy
Formatted JS Size: 0.08 KB
function square(x) {
  // return square of x
  return x * x;
}

console.log(square(5));

Minified JS

Copy
Compressed JS Size: 0.05 KB
function square(e){return e*e}console.log(square(5));

Example 2: Modern features and classes

Original JS

Copy
Formatted JS Size: 0.73 KB
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)

Copy
Minified JS Size: 0.61 KB
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

Copy
Formatted JS Size: 0.23 KB
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)

Copy
Minified JS Size: 0.14 KB
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.

OptionDefaultDescription
ECMAScript VersionES5 (2009)Target language level for output compatibility
EncloseFalseWrap output in a top-level function closure
Mangle NamesTrueShorten variable and property names to save bytes
Keep ClassnamesFalsePreserve class names when mangling identifiers
Keep Function NamesFalsePreserve function names for clearer stack traces
Bare ReturnsTrueAllow return statements outside functions in parsing
HTML5 CommentsTruePreserve HTML5-style comments when parsing
ShebangTrueSupport parsing of shebang lines (#!) in scripts
Arrow OptimizationTrueConvert functions to arrow syntax where safe
Unsafe ArrowsFalseConvert ES5 function expressions into ES6 arrow functions
Collapse VarsTrueMerge single-use variable definitions to reduce code
Reduce VarsTrueOptimize repeated variable references by reusing values
Join VarsTrueCombine consecutive variable declarations into a single statement
Passes1Number of times compress optimizations are applied
ComparisonsTrueSimplify comparison expressions for smaller output
Unsafe ComparisonsFalseAllow potentially unsafe optimizations on comparisons
ConditionalsTrueTransform conditional statements for compactness
Dead Code RemovalTrueStrip unreachable code blocks from the bundle
Unused RemovalTrueRemove unused variables and functions
DirectivesTrueApply directives like "use strict" where possible
Drop ConsoleFalseRemove console statements from the code
Drop DebuggerTrueRemove debugger statements from the code
EvaluateTrueCompute constant expressions at build time
Hoist PropertiesTrueMove static object properties to reduce repeated lookups
Top-level OptimizationFalseOptimize variables and functions declared in the top scope
Preserve InfinityTrueKeep literal Infinity instead of replacing with 1/0
If ReturnTrueOptimize if statements followed by return for compactness
InlineTrueInline functions where beneficial
Reduce FunctionsTrueOptimize repeated function expressions
SequencesTrueUse sequence expressions to merge statements
Side EffectsTrueDrop expressions without side effects
Switch OptimizationsTrueOptimize switch statements for smaller code
Typeof OptimizationsTrueOptimize typeof expressions when safe
ASCII OnlyFalseEscape non-ASCII characters in output
BeautifyFalseFormat output code for readability instead of minifying
Always BracesFalseForce curly braces on blocks for consistent style
Preserve CommentsNoneKeep selected comments such as licensing or banner text
Banner CommentEmptyText to prepend to the optimized file for identification

Best Practices For JS Minification

  • Keep original code in version control
  • Minify JS for production only and 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.