πŸ“¦

Minify JavaScript

Minify and compress JavaScript code to reduce file size for production. Remove comments, whitespace, and optimize code for faster loading.

Developer Tools
Loading tool...

How to Use Minify JavaScript

Quick Start Guide

  1. Paste Code: Copy your JavaScript code into the input area
  2. Configure Options: Choose which optimizations to apply (comments, whitespace, etc.)
  3. Minify: Click "Minify Code" to compress your JavaScript
  4. Review Savings: See compression percentage and size reduction
  5. Copy or Download: Use the output buttons to save your minified code
  6. Try Examples: Click example buttons to see different minification scenarios

What is JavaScript Minification?

JavaScript minification is the process of removing unnecessary characters from source code without changing its functionality. This includes removing whitespace, comments, line breaks, and optionally shortening variable names to create the smallest possible file size.

Purpose: Reduce file size, improve loading speed, optimize bandwidth Input: Readable, formatted JavaScript with comments Output: Compressed, single-line JavaScript (minimal size) Usage: Production deployment, CDN distribution, performance optimization

Why Minify JavaScript?

Performance Benefits:

  • Faster Downloads: Smaller files download faster (30-70% reduction typical)
  • Better Page Load: Less JavaScript = faster page rendering
  • Reduced Bandwidth: Lower data transfer costs
  • Improved SEO: Faster sites rank better in search results
  • Better UX: Quicker interactive time for users
  • Mobile Optimization: Critical for slower mobile connections

Common Scenarios:

  • Deploying JavaScript to production websites
  • Optimizing scripts for CDN distribution
  • Reducing bundle sizes in web applications
  • Improving Core Web Vitals scores
  • Meeting performance budgets
  • Optimizing third-party script delivery

Development vs Production Code

Development Code (readable):

// Calculate the sum of two numbers
function calculateSum(a, b) {
  // Return the sum
  return a + b;
}

const result = calculateSum(5, 10);
console.log(result);

Production Code (minified):

function calculateSum(a,b){return a+b}const result=calculateSum(5,10);console.log(result);

Size Comparison:

  • Development: 168 bytes
  • Production: 85 bytes
  • Savings: 49.4% reduction

Minification Options Explained

Remove Comments

What it does: Strips out all single-line (//) and multi-line (/* */) comments

Before:

// This is a comment
function test() {
  /* Multi-line
     comment */
  return true;
}

After:

function test(){return true;}

When to enable: Always for production (comments add no value to executed code)

Remove Whitespace

What it does: Removes spaces, tabs, and line breaks that aren't needed for code execution

Before:

const numbers = [1, 2, 3];

const doubled = numbers.map(num => {
  return num * 2;
});

After:

const numbers=[1,2,3];const doubled=numbers.map(num=>{return num*2;});

When to enable: Always for production (biggest size reduction)

Shorten Variables

What it does: Renames long variable names to shorter versions (basic implementation)

Before:

const userName = "John";
const userEmail = "john@example.com";

After:

const _0="John";const _1="john@example.com";

When to enable: For maximum compression (use with caution, may affect debugging)

⚠️ Warning: Basic variable shortening may not handle all scope rules correctly. For production, use professional tools like Terser or UglifyJS.

Remove console.*

What it does: Strips out all console.log(), console.warn(), console.error(), etc.

Before:

function processData(data) {
  console.log("Processing:", data);
  const result = transform(data);
  console.warn("Result:", result);
  return result;
}

After:

function processData(data){const result=transform(data);return result;}

When to enable: For production (remove debug statements, slight security improvement)

Preserve Strings

What it does: Keeps all string content intact (always enabled for safety)

Why it matters: Strings may contain important data like HTML templates, SQL queries, or user messages that must not be modified.

Example of what NOT to do:

const template = "Hello,   World!  ";  // Multiple spaces intentional
// WRONG: Minifying string content would break it
// RIGHT: Preserve string exactly as-is

Common Use Cases

1. Production Website Deployment

Purpose: Optimize JavaScript before deploying to production

Scenario: You have a 50KB JavaScript file for your website. Minifying it reduces to 30KB, saving 20KB per page load.

Settings:

  • βœ… Remove comments
  • βœ… Remove whitespace
  • ❌ Shorten variables (optional, use Terser for production)
  • βœ… Remove console statements
  • βœ… Preserve strings

Impact:

  • Before: 50 KB
  • After: 30 KB (40% reduction)
  • On 10,000 page views: 200 MB bandwidth saved
  • Faster page loads, better user experience

2. CDN Distribution

Purpose: Minimize file size for Content Delivery Network hosting

Scenario: Distributing a JavaScript library via CDN (like jQuery, React, etc.)

Process:

  1. Develop with readable, commented code
  2. Minify for production
  3. Upload library.min.js to CDN
  4. Users download smallest possible file

Naming convention: library.min.js (industry standard)

3. Improving Core Web Vitals

Purpose: Reduce JavaScript bundle size to improve Google Page Speed scores

Metrics affected:

  • LCP (Largest Contentful Paint): Smaller JS = faster rendering
  • FID (First Input Delay): Less JS to parse = faster interactive
  • CLS (Cumulative Layout Shift): Faster JS execution = less layout shift

Typical improvement: 30-50% reduction in JS size

4. Mobile Optimization

Purpose: Optimize for slow mobile connections (3G, 4G)

Why it matters:

  • Mobile users often have slower connections
  • 100KB of JS on 3G can take 5+ seconds
  • Minified 60KB version takes 3 seconds (40% faster)

Best practice: Minify + compress (gzip/brotli) for maximum mobile performance

5. Bundle Size Reduction

Purpose: Keep application bundles under performance budgets

Scenario: Your React app bundle is 250KB. Performance budget is 200KB.

Solution:

  1. Minify all JavaScript
  2. Remove console statements
  3. Use tree-shaking (in bundler)
  4. Code-splitting for routes

Result: 250KB β†’ 160KB (36% reduction)

6. Third-Party Script Optimization

Purpose: Optimize scripts before embedding on client sites

Scenario: You provide a widget for other websites to embed

Benefits for clients:

  • Minimal impact on their page load times
  • Smaller bandwidth usage
  • Better page speed scores
  • Professional appearance

Features

Core Functionality

  • Comment Removal: Strip all comments (single-line and multi-line)
  • Whitespace Removal: Remove spaces, tabs, line breaks
  • Variable Shortening: Basic variable name compression (use with caution)
  • Console Removal: Strip debug statements
  • String Preservation: Never modify string content
  • Size Statistics: Real-time compression ratio display

Supported JavaScript

  • ES5: Traditional JavaScript syntax
  • ES6+: Arrow functions, destructuring, template literals
  • Classes: ES6 class syntax
  • Async/Await: Modern async patterns
  • JSX: React component code (basic)
  • CommonJS/ESM: Import/export statements

Output Features

  • Compression Ratio: Shows percentage reduction
  • Before/After Stats: Lines, characters, file size
  • Copy to Clipboard: One-click copying
  • Download File: Save as .min.js
  • Live Preview: See minified code instantly

Best Practices

1. Development vs Production Workflow

Never edit minified code directly!

Correct workflow:

1. Write code (development, readable, commented)
   ↓
2. Test thoroughly
   ↓
3. Minify for production
   ↓
4. Deploy minified version
   ↓
5. Keep original source for future edits

Wrong workflow:

❌ Edit minified code
❌ Minify during development
❌ Lose original source

2. Always Keep Source Files

Best practice:

  • script.js β†’ Original source (keep in version control)
  • script.min.js β†’ Minified production version (generated)

Version control:

src/
  β”œβ”€β”€ script.js          # Commit this
  └── script.min.js      # Don't commit (regenerate on deploy)

3. Use Source Maps for Debugging

When minifying, generate source maps to debug production issues:

script.min.js           # Minified code
script.min.js.map       # Source map (links to original)

Browser DevTools can use source maps to show original code when debugging minified production code.

Note: This simple minifier doesn't generate source maps. Use Terser, UglifyJS, or webpack for source map support.

4. Combine with Compression

Layer optimizations:

  1. Minify: Remove unnecessary characters
  2. Gzip/Brotli: Server-side compression

Example:

  • Original: 100 KB
  • Minified: 60 KB (40% reduction)
  • Minified + Gzip: 20 KB (67% additional reduction)
  • Total savings: 80% smaller than original

How to enable: Configure your web server (Apache, Nginx) or hosting to compress JavaScript files.

5. Testing After Minification

Always test minified code before deploying!

Testing checklist:

  • All features work correctly
  • No JavaScript errors in console
  • Forms submit properly
  • Interactive elements respond
  • API calls succeed
  • No broken functionality

Common issues:

  • Missing semicolons (ASI edge cases)
  • Variable scope issues (if using variable shortening)
  • Regex issues (rare)

6. Professional Tools for Production

This tool is great for:

  • Quick minification
  • Small scripts
  • Learning about minification
  • One-off optimization

For production projects, use:

  • Terser: Industry standard, used by webpack
  • UglifyJS: Mature, widely used
  • esbuild: Extremely fast bundler + minifier
  • Webpack: Build tool with minification
  • Vite: Modern build tool with automatic minification

Why professional tools:

  • Full AST parsing (100% accurate)
  • Source map generation
  • Advanced optimizations (tree-shaking, dead code elimination)
  • Variable mangling (safe renaming)
  • Scope analysis (proper variable handling)

Technical Details

How Minification Works

1. Remove all comments (//, /* */)
2. Remove console.* statements (if enabled)
3. Parse code character by character
4. Track string boundaries (preserve string content)
5. Remove whitespace between tokens
6. Keep minimal spacing where required (syntax)
7. Optionally shorten variable names
8. Output compressed single-line code

What Gets Removed

Removed:

  • βœ‚οΈ Comments (// and /* */)
  • βœ‚οΈ Line breaks (\n, \r)
  • βœ‚οΈ Extra spaces and tabs
  • βœ‚οΈ Unnecessary whitespace around operators
  • βœ‚οΈ Console statements (optional)

Preserved:

  • βœ… All string content (exact)
  • βœ… Variable names (unless shortening enabled)
  • βœ… Code logic and functionality
  • βœ… Minimal required spacing

Compression Comparison

Typical compression rates:

  • Well-commented code: 40-60% reduction
  • Average code: 30-50% reduction
  • Already clean code: 20-30% reduction
  • Minified code: 0-10% reduction (already optimized)

Example savings:

Original SizeMinified SizeSavings
100 KB60 KB40%
50 KB32 KB36%
20 KB13 KB35%
10 KB7 KB30%

Limitations

This is a basic minifier:

  • Character-based parsing (not full AST)
  • Basic variable shortening (may have scope issues)
  • No advanced optimizations
  • No source map generation
  • No tree-shaking or dead code elimination

For production, use professional tools that provide:

  • Full abstract syntax tree (AST) parsing
  • Safe variable renaming (mangling)
  • Dead code elimination
  • Tree-shaking (remove unused code)
  • Source map generation
  • Advanced optimizations

This tool is perfect for:

  • Learning about minification
  • Quick one-off minification
  • Small scripts and widgets
  • Understanding compression benefits

Performance Impact

File Size Savings

Real-world examples:

jQuery (development vs production):

  • Development: 287 KB
  • Minified: 89 KB
  • Savings: 69% (198 KB saved)

React (development vs production):

  • Development: 120 KB
  • Minified: 42 KB
  • Savings: 65% (78 KB saved)

Your script (typical):

  • Development: 50 KB
  • Minified: 32 KB
  • Savings: 36% (18 KB saved)

Page Load Impact

Download time comparison (50 KB file):

ConnectionOriginalMinifiedImprovement
Fast 4G0.3s0.2s33% faster
3G2.5s1.5s40% faster
Slow 3G8.0s5.0s37% faster

SEO Benefits

Google PageSpeed Insights:

  • Smaller JS improves performance score
  • Better mobile scores (critical ranking factor)
  • Improved Core Web Vitals metrics
  • Higher search rankings for better performance

Best practice: Combine minification with:

  • Compression (gzip/brotli)
  • Caching headers
  • CDN delivery
  • Code splitting

Troubleshooting

Issue: Code breaks after minification

Possible causes:

  1. Missing semicolons + automatic semicolon insertion (ASI) issues
  2. Variable shortening renamed variables incorrectly
  3. Code relied on specific whitespace (rare)

Solutions:

  • Disable variable shortening
  • Add explicit semicolons in original code
  • Test minified code before deploying
  • Use professional tools (Terser) for production
  • Check browser console for errors

Issue: Minimal or no size reduction

Possible causes:

  1. Code already minified
  2. Lots of string content (preserved)
  3. Minimal comments/whitespace in original

Solutions:

  • Check if you're minifying already-minified code
  • Use compression (gzip) for additional savings
  • This is normal for already-optimized code

Issue: Console statements still present

Solution:

  • Enable "Remove console.*" option
  • Re-minify the code

Issue: Need source maps for debugging

Solution:

  • This simple tool doesn't generate source maps
  • Use professional tools: Terser, UglifyJS, webpack, Vite
  • These tools generate .map files for debugging

Issue: Variables renamed incorrectly

Solution:

  • Disable "Shorten Variables" option
  • Use professional tools with proper scope analysis
  • Variable shortening in this tool is basic (use with caution)

Browser Compatibility

Supported browsers:

  • βœ… Chrome 90+ (recommended)
  • βœ… Firefox 88+
  • βœ… Safari 14+
  • βœ… Edge 90+
  • βœ… Opera 76+

Required features:

  • ES6+ JavaScript support
  • Clipboard API (for copy)
  • Blob API (for download)
  • Modern CSS (for UI)

Works on:

  • Desktop: Windows, macOS, Linux
  • Mobile: iOS Safari, Chrome Android (paste/copy supported)
  • Tablets: iPad, Android tablets

Privacy & Security

Client-Side Processing

  • 100% Local: All minification in your browser
  • No Uploads: Code never sent to servers
  • No Storage: Nothing saved or cached
  • No Tracking: No analytics on your code
  • No Accounts: No login required

Security Features

  • Sandboxed: Browser security sandbox
  • No Execution: Code never executed
  • Safe Parsing: Character-based, not eval
  • No External Calls: No network requests

Safe for Sensitive Code

  • βœ… Proprietary code
  • βœ… Client projects
  • βœ… Production code
  • βœ… Commercial applications

Important: While minification makes code harder to read, it's NOT security. Anyone can beautify minified code. Never rely on minification for security - use proper authentication, authorization, and server-side validation.

Comparison with Other Tools

JavaScript Minifier vs Terser

JavaScript Minifier (this tool):

  • βœ… Browser-based, instant
  • βœ… No installation
  • βœ… Simple, straightforward
  • βœ… Perfect for learning
  • ❌ Basic parsing
  • ❌ No source maps
  • ❌ Limited optimizations

Terser:

  • βœ… Industry standard
  • βœ… Full AST parsing
  • βœ… Source maps
  • βœ… Advanced optimizations
  • βœ… Safe variable mangling
  • ❌ Requires npm/installation
  • ❌ Command-line tool

When to use this tool: Quick minification, learning, small scripts

When to use Terser: Production projects, professional development, maximum optimization

JavaScript Minifier vs UglifyJS

Similar to Terser comparison

UglifyJS is the older standard, Terser is the modern replacement (ES6+ support).

JavaScript Minifier vs Build Tools

Build tools (Webpack, Vite, esbuild):

  • Automatic minification during build
  • Integrated with development workflow
  • Source maps included
  • Tree-shaking and code splitting
  • Bundle optimization

This tool: Manual, one-off minification

Best practice: Use build tools for projects, this tool for quick tasks

Integration Tips

Using Minified Code in Projects

1. Manual Workflow:

1. Edit source.js (development)
2. Minify using this tool
3. Download source.min.js
4. Upload to server/CDN
5. Link in HTML: <script src="source.min.js">

2. HTML Integration:

<!-- Development -->
<script src="js/app.js"></script>

<!-- Production -->
<script src="js/app.min.js"></script>

3. Version Control:

.gitignore:
  *.min.js
  *.min.js.map

README.md:
  "Run build script to generate minified files"

Setting Up Build Process

For serious projects, automate minification:

Option 1: npm scripts

{
  "scripts": {
    "build": "terser src/app.js -o dist/app.min.js --source-map"
  }
}

Option 2: Webpack

// webpack.config.js
module.exports = {
  mode: 'production',  // Automatic minification
  // ...
}

Option 3: Vite

// vite.config.js
export default {
  build: {
    minify: 'terser'  // Automatic
  }
}

Quick Reference

Recommended Settings by Use Case

Standard Production Deployment:

  • βœ… Remove comments
  • βœ… Remove whitespace
  • ❌ Shorten variables (use Terser instead)
  • βœ… Remove console statements
  • βœ… Preserve strings

Maximum Compression (use with testing):

  • βœ… Remove comments
  • βœ… Remove whitespace
  • βœ… Shorten variables (test thoroughly!)
  • βœ… Remove console statements
  • βœ… Preserve strings

Learning/Understanding:

  • βœ… Remove comments only (see the difference)
  • Then try enabling other options one by one

Quick Cleanup:

  • βœ… Remove comments
  • βœ… Remove console statements
  • ❌ Keep whitespace for readability

File Naming Convention

Industry standard:

  • library.js β†’ Original source
  • library.min.js β†’ Minified version

Examples in the wild:

  • jquery-3.6.0.min.js
  • react.production.min.js
  • bootstrap.min.js

Your files:

  • app.js β†’ app.min.js
  • utils.js β†’ utils.min.js

Note: For production projects, we strongly recommend using professional minification tools like Terser, UglifyJS, or build tool plugins (Webpack, Vite, esbuild) which provide advanced optimizations, source maps, and guaranteed correctness. This tool is perfect for quick minification, learning, and simple scripts.

Frequently Asked Questions

Related Utility Tools

Share Your Feedback

Help us improve this tool by sharing your experience

We will only use this to follow up on your feedback