Minify JavaScript
Minify and compress JavaScript code to reduce file size for production. Remove comments, whitespace, and optimize code for faster loading.
Developer ToolsHow to Use Minify JavaScript
Quick Start Guide
- Paste Code: Copy your JavaScript code into the input area
- Configure Options: Choose which optimizations to apply (comments, whitespace, etc.)
- Minify: Click "Minify Code" to compress your JavaScript
- Review Savings: See compression percentage and size reduction
- Copy or Download: Use the output buttons to save your minified code
- 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:
- Develop with readable, commented code
- Minify for production
- Upload
library.min.jsto CDN - 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:
- Minify all JavaScript
- Remove console statements
- Use tree-shaking (in bundler)
- 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:
- Minify: Remove unnecessary characters
- 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 Size | Minified Size | Savings |
|---|---|---|
| 100 KB | 60 KB | 40% |
| 50 KB | 32 KB | 36% |
| 20 KB | 13 KB | 35% |
| 10 KB | 7 KB | 30% |
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):
| Connection | Original | Minified | Improvement |
|---|---|---|---|
| Fast 4G | 0.3s | 0.2s | 33% faster |
| 3G | 2.5s | 1.5s | 40% faster |
| Slow 3G | 8.0s | 5.0s | 37% 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:
- Missing semicolons + automatic semicolon insertion (ASI) issues
- Variable shortening renamed variables incorrectly
- 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:
- Code already minified
- Lots of string content (preserved)
- 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
.mapfiles 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 sourcelibrary.min.jsβ Minified version
Examples in the wild:
jquery-3.6.0.min.jsreact.production.min.jsbootstrap.min.js
Your files:
app.jsβapp.min.jsutils.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
Temperature Converter
FeaturedConvert temperatures between Celsius, Fahrenheit, and Kelvin instantly with live conversion
Use Tool βUnit Converter
FeaturedConvert between length, weight, and volume units instantly. Support for metric and imperial systems.
Use Tool βWord Counter
FeaturedCount words, characters, sentences, and reading time instantly
Use Tool βArea Converter
FeaturedConvert areas between square feet, square meters, acres, hectares, and square yards instantly
Use Tool βTime Zone Converter
FeaturedConvert between time zones and see current or custom time across different parts of the world
Use Tool βSpeed Converter
FeaturedConvert speeds between miles per hour (MPH), kilometers per hour (KPH), and knots instantly
Use Tool βPaper Size Converter
Convert between international paper sizes (A4, Letter, Legal) with dimensions in mm, cm, and inches. Compare ISO A/B series and North American paper standards.
Use Tool βPPI Calculator
Calculate PPI (pixels per inch) for screens and displays. Find pixel density from resolution and screen size for phones, tablets, monitors, and TVs.
Use Tool βShare Your Feedback
Help us improve this tool by sharing your experience