Online JavaScript Minifier: Reduce JS File Size for Faster Page Loads
What Is JavaScript Minification
JavaScript minification removes unnecessary characters from JS files (whitespace, comments, short variable names) to reduce file size. Advanced tools also perform code optimizations like dead code elimination and constant folding. Paste your script into our JavaScript Minifier to strip bytes instantly without changing behavior.
Before and After
Before:
// Calculate sum of two numbers
function addNumbers(a, b) {
// Return the sum
var result = a + b;
return result;
}
var x = 10;
var y = 20;
console.log(addNumbers(x, y));
After:
function addNumbers(a,b){return a+b}console.log(addNumbers(10,20));
Why You Need JS Minification
- JavaScript is the largest resource: Typically 40-70% of total page size
- High compression rate: Usually 40-70% reduction
- JS is parse-blocking: Smaller files = faster parsing and execution
- Improves Core Web Vitals: Reduces LCP (Largest Contentful Paint)
- Saves CDN bandwidth: Significant bandwidth cost reduction
- Mobile optimization: Mobile CPUs parse slower, making compression critical
JS Minification Strategies
| Strategy | Description | Example |
|----------|-------------|---------|
| Remove whitespace | Collapse spaces, breaks, indentation | — |
| Remove comments | Delete single/multi-line comments | — |
| Variable mangling | Shorten local variable names | result → r |
| Dead code elimination | Remove unreachable code | — |
| Constant folding | Compute constant expressions at compile time | 2+3 → 5 |
| Function inlining | Replace simple calls with function body | — |
| Property dot notation | obj["name"] → obj.name | — |
How to Use an Online Tool
Using ToolVault's JavaScript Minifier:
- Paste JavaScript code
- Select options (variable mangling, dead code elimination, etc.)
- Real-time display of minified code
- Shows compression ratio and bytes saved
JS Minification in Build Tools
Webpack (TerserPlugin)
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
pure_funcs: ['console.log']
},
mangle: true
}
})
]
}
};
Vite
import { defineConfig } from 'vite';
export default defineConfig({
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
}
});
esbuild (Vite default)
import { defineConfig } from 'vite';
export default defineConfig({
build: {
minify: 'esbuild' // 10-100x faster than terser
}
});
JS Minifier Comparison
| Tool | Speed | Compression | Ecosystem | |------|-------|-------------|-----------| | esbuild | Extremely fast | Good | Vite default | | terser | Medium | Best | Webpack default | | SWC | Fast | Good | Next.js default | | uglify-js | Medium | Good | Classic tool |
FAQ
Can I Debug Minified Code?
Minified code is hard to read. Solution: generate Source Map files. Browser dev tools can display original code via Source Map while using minified version in production.
Why Remove console.log?
console.log statements:
- Take up extra space
- Leak debug info in production
- Have minor performance overhead
Use terser's drop_console: true config to auto-remove.
Should I Choose esbuild or terser?
Prefer esbuild: 10-100x faster, ideal for large projects. Use terser for fine-grained control (custom obfuscation). Vite defaults to esbuild; Webpack defaults to terser.
This article is brought to you by ToolVault. More developer tools at the homepage.
Related Tools
Related Articles
How to Fix 'Hydration failed / Text content does not match' in Next.js
The complete guide to Next.js/React SSR hydration errors: why server and client renders diverge, the three usual suspects (timestamps, random values, localStorage), correct suppressHydrationWarning usage, and a ClientOnly pattern for browser-only widgets.
How to Fix 'Cannot read properties of undefined (reading map)'
A complete debugging guide for the most common React runtime error: why undefined.map throws, handling async data correctly, optional chaining and default guards, empty-state rendering, and using our JSON tools to inspect the real payload.
How to Convert JSON to Java Entity Class (with annotations and List nesting)
Got JSON API data and want the matching Java POJO? Learn JSON-to-Java type mapping and common annotations, and step-by-step how to generate serializable classes locally.