Use JavaScript Compressor

Enter your data below to use the JavaScript Compressor

📌 Try these examples:
RESULT

Last updated

Example: Variable Name Mangling

// Before:
function processUserAuthentication(userCredentials, authenticationConfig) {
  const hashedPassword = hashFunction(userCredentials.password);
  const isValidUser = checkDatabase(userCredentials.username, hashedPassword);
  const sessionToken = generateToken(authenticationConfig.secretKey);
  return { isValidUser, sessionToken };
}

// After (with mangling):
function processUserAuthentication(a,b){const c=hashFunction(a.password),d=checkDatabase(a.username,c),e=generateToken(b.secretKey);return{isValidUser:d,sessionToken:e}}

Example: Dead Code Elimination

// Before (with dead code):
function getEnvironment() {
  const env = 'production';
  
  if (false) {
    console.log('This never runs');
    return 'debug';
  }
  
  if (env === 'development') {
    return 'dev';  // unreachable — env is always 'production'
  }
  
  return env;
}

// After (dead code removed):
function getEnvironment(){return"production"}

Example: Constant Folding

// Before:
const SECONDS_PER_MINUTE = 60;
const MINUTES_PER_HOUR = 60;
const HOURS_PER_DAY = 24;
const SECONDS_PER_DAY = SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY;
const MS_PER_DAY = SECONDS_PER_DAY * 1000;

// After (constants folded at compile time):
const MS_PER_DAY=86400000;

Example: Comment Stripping

// Before (with comments, 580 bytes):
/**
 * Validates an email address format.
 * @param {string} email - The email to validate
 * @returns {boolean} True if valid, false otherwise
 */
function isValidEmail(email) {
  // RFC 5322 compliant regex
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  
  // Check if email is a string
  if (typeof email !== 'string') {
    return false;
  }
  
  // Test against regex
  return emailRegex.test(email.toLowerCase());
}

// After (comments stripped, 121 bytes):
function isValidEmail(e){return typeof e==="string"&&/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.toLowerCase())}

Example: License Comment Preservation

// Before:
/*!
 * MyLibrary v2.1.0
 * (c) 2024 Example Corp
 * Released under the MIT License
 */

// Regular comment — will be removed
function add(a, b) {
  return a + b;
}

// After (license comment preserved):
/*!
 * MyLibrary v2.1.0
 * (c) 2024 Example Corp
 * Released under the MIT License
 */
function add(a,b){return a+b}
File: app.js

Original size:        245,820 bytes (240 KB)
After whitespace:     178,340 bytes (174 KB) — 27% reduction
After comments:       165,210 bytes (161 KB) — 33% reduction
After mangling:       142,880 bytes (140 KB) — 42% reduction
After dead code:      138,450 bytes (135 KB) — 44% reduction
Final minified:       138,450 bytes (135 KB) — 44% reduction

Estimated gzip:        42,300 bytes (41 KB)  — 83% reduction
Estimated brotli:      36,100 bytes (35 KB)  — 85% reduction
// Minified output (app.min.js):
function a(b,c){if(c<0||c>100)throw new Error("Invalid");return b*(1-c/100)}
//# sourceMappingURL=app.min.js.map

// Source map (app.min.js.map) maps back to original:
{
  "version": 3,
  "sources": ["app.js"],
  "names": ["calculateDiscount", "price", "discountPercent"],
  "mappings": "AAAA,SAASA,kBAAkBC,EAAOC..."
}

// In browser DevTools, the debugger shows the original:
function calculateDiscount(price, discountPercent) {
  if (discountPercent < 0 || discountPercent > 100) throw new Error("Invalid");
  return price * (1 - discountPercent / 100);
}

Batch Compression Results

Processing 5 files...

File                  Original    Minified    Savings
app.js                240 KB      135 KB      44%
vendor.js             820 KB      410 KB      50%
utils.js               45 KB       22 KB      51%
components.js         180 KB       98 KB      46%
router.js              28 KB       14 KB      50%

Total                1,313 KB     679 KB      48%
Estimated gzip         390 KB     195 KB      50%

Paste your JavaScript code or upload a file to compress it. The compressor preserves all functionality while achieving the maximum possible size reduction for faster page loads.

Example: Basic Minification

// Before (formatted, 312 bytes):
function calculateDiscount(price, discountPercent) {
  if (discountPercent < 0 || discountPercent > 100) {
    throw new Error('Discount must be between 0 and 100');
  }
  const discountAmount = price * (discountPercent / 100);
  const finalPrice = price - discountAmount;
  return Math.round(finalPrice * 100) / 100;
}

// After (minified, 148 bytes — 53% reduction):
function calculateDiscount(e,t){if(t<0||t>100)throw new Error("Discount must be between 0 and 100");return Math.round((e-e*(t/100))*100)/100}

Example: ES6+ to ES5 Transpilation + Minification

// Before (ES6+):
const greet = (name = 'World') => `Hello, ${name}!`;
const users = ['Alice', 'Bob', 'Charlie'];
const greetings = users.map(greet);

// After (transpiled to ES5 + minified):
var greet=function(n){return"Hello, "+(n===void 0?"World":n)+"!"};var greetings=["Alice","Bob","Charlie"].map(greet);

Frequently Asked Questions

Simply enter your data, click the process button, and get instant results. All processing happens in your browser for maximum privacy and security.

Yes! JavaScript Compressor is completely free to use with no registration required. All processing is done client-side in your browser.

Absolutely! All processing happens locally in your browser. Your data never leaves your device, ensuring complete privacy and security.