📦 JavaScript Minifier

⚙️
🎛️
📝
📦
📊
Original Size: {{ statistics.originalSize }} bytes
Original Lines: {{ statistics.originalLines }}
Characters Saved: {{ statistics.bytesSaved }}
Minified Size: {{ statistics.minifiedSize }} bytes
Minified Lines: {{ statistics.minifiedLines }}
Compression Ratio: {{ statistics.compressionRatio }}%
Bandwidth Savings: {{ formatBytes(statistics.bytesSaved) }} per request • Load Time: ~{{ estimateLoadTime(statistics.bytesSaved) }}ms faster on 3G
📋
{{ item.type ==='success' ?'✅' : item.type ==='warning' ?'⚠️' :'ℹ️' }} {{ item.message }}
⚠️ {{ error }}

ℹ️ About JavaScript Minifier

JavaScript Minifier compresses JavaScript source by removing comments, collapsing whitespace, stripping optional debugging statements, and optionally shortening local variable names. It is useful when you need a quick browser-side pass before testing, sharing a snippet, or estimating how much smaller a script can become after minification.

JavaScript syntax is defined by the ECMAScript lexical grammar, where whitespace and comments are normally separate tokens from executable code. Production minifiers use that distinction, plus parser-aware transforms such as the ones documented by Terser, to reduce bytes while preserving behavior. This tool focuses on straightforward, readable transformations you can inspect immediately in the output pane.

Practical uses:

  • Paste a small script and create a compact version for demos, documentation, or static pages.
  • Compare original and minified byte counts before adding JavaScript to a page budget.
  • Remove temporary console.log and debugger statements before sharing sample code.
  • Check how whitespace, comments, and simple variable mangling affect load size.

What the modes do:

  • Basic: removes comments, debug statements, and extra spacing while leaving variable names intact.
  • Standard: adds simple variable-name mangling for declared var, let, and const identifiers.
  • Aggressive: enables the same mangling and attempts limited cleanup of empty functions and unreachable code after return.

Example input:

// total helper
function total(items) {
    let sum = 0;
    for (const item of items) {
        console.log('item', item.name);
        sum += item.price;
    }
    return sum;
}

Example minified output:

function total(items){let a0=0;for(const a1 of items){a0+=a1.price}return a0}

Limitations: minification can change behavior if code depends on function names, variable names, comments, exact formatting, or unusual syntax patterns. For production bundles, run your test suite and use a parser-based build tool such as Terser, esbuild, Rollup, or webpack. Treat the size estimate as a quick byte-count preview, not a substitute for gzip or Brotli compression measurements.

API Usage Example:

POST /api/tools/webdev/js-minifier
Content-Type: application/json

{
    "code": "function foo(a, b) {\n  return a + b;\n}",
    "level": "standard",
    "removeComments": true,
    "removeConsole": false,
    "removeDebugger": true,
    "mangleVariables": true,
    "removeUnusedCode": false
}
Ready