JavaScript Minifier
Compress and minify JavaScript code online to reduce file size. Remove whitespace, comments, and shorten variables for faster loading.
About JavaScript Minifier
This JavaScript Minifier removes comments, whitespace, and unnecessary characters from your JS code. Smaller JavaScript files mean faster page loads and better user experience. This is a basic minifier - for production, consider tools like Terser or UglifyJS.
How to Use JavaScript Minifier
Paste or upload JavaScript
Paste your JavaScript into the input editor, or click Upload to pick a .js file. The minifier accepts complete files, modules, classes, functions, or snippets.
View minified output
The minified version appears instantly in the output panel — all unnecessary whitespace removed, comments stripped, producing compact production-ready code.
Check the savings
Below the output, the Saved % stat shows your exact size reduction. Most formatted JavaScript saves 30-50% from whitespace alone; production-grade minification with name mangling saves 50-70%.
Copy or download
Click Copy to put minified JS on your clipboard, or Download as .js. Drop into production builds, inline into HTML, or use as a CDN asset to reduce bundle size and improve Time-to-Interactive.
When to Use JavaScript Minifier
Reducing JavaScript bundle size
JavaScript is the most expensive resource on most websites — it must be downloaded, parsed, and executed before pages become interactive. Minifying production JS saves 30-60% off file size, directly reducing parse time, execution time, and Time-to-Interactive (TTI) — a key Core Web Vital for SEO and user experience.
Inlining critical JavaScript
Small inline scripts in <head> (analytics, A/B testing, feature flags, theme detection) execute synchronously and block rendering. Minifying these inline scripts reduces head section size and time-to-paint. Critical for landing pages and SPAs where every millisecond before first paint matters.
Sending JS in service worker assets
Service workers cache JavaScript for offline use — smaller cached files mean less storage on user devices and faster restoration when offline. Minifying assets bundled into service workers (workbox-managed assets, AppCache fallback) reduces installation time and update overhead for PWAs.
Embedding JavaScript in JSON or HTML
When inlining JavaScript into JSON config (manifest.json, package metadata), Markdown code blocks, or HTML <script> tags in templates, minified JS fits more functionality in less space. Useful for AMP pages, email-embedded scripts (where supported), and tightly size-constrained contexts.
JavaScript Minifier Examples
Function with comments to minified
// Add two numbers
function add(a, b) {
// Returns the sum
return a + b;
}
// Test it
console.log(add(2, 3));function add(a,b){return a+b}console.log(add(2,3));Comments are stripped, whitespace collapsed, and unnecessary semicolons cleaned up where ASI (automatic semicolon insertion) handles it. The 124-character formatted code becomes 50 characters — a 60% reduction. Runtime behavior is identical: the JavaScript engine parses both into the same AST.
Class minification
class Counter {
constructor(start = 0) {
this.count = start;
}
increment() {
this.count++;
}
getValue() {
return this.count;
}
}class Counter{constructor(start=0){this.count=start}increment(){this.count++}getValue(){return this.count}}All class methods stay intact with their original names and parameters. Only whitespace inside method bodies and between methods is removed. The 187-character formatted class becomes 110 characters — 41% reduction. Property access (this.count) is preserved exactly.
Modern async function
async function fetchUser(id) {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error('User not found');
}
return response.json();
}async function fetchUser(id){const response=await fetch(`/api/users/${id}`);if(!response.ok)throw new Error('User not found');return response.json()}Modern features (async/await, template literals) are preserved exactly. The if-block becomes a single line because the if-throw pattern doesn't need braces with one statement. Identifiers (response, fetchUser, id) are preserved — basic minification doesn't mangle names.
Tips & Best Practices for JavaScript Minifier
- 1.Always pair JavaScript minification with HTTP compression (gzip or brotli) for maximum effect. Minified + brotli-compressed JS is typically 80-90% smaller than formatted source — much better than either alone.
- 2.Don't minify development code. Keep source in version control formatted for diffs, code reviews, and IDE comprehension. Only minify as a build step. Modern build tools (webpack, vite, parcel, esbuild) automate this.
- 3.Watch the Saved % stat: anything below 15% means your input was already nearly minified. Additional savings should come from gzip rather than further character removal.
- 4.For maximum minification beyond whitespace removal, use Terser or esbuild in production builds — they perform variable name mangling, dead code elimination, expression simplification, and tree-shaking that this online tool doesn't do.
- 5.If you use eval() or 'with' statements, name mangling can break your code (since identifiers might be looked up by string). Modern minifiers detect these patterns and skip mangling for affected scopes — but it's a good reason to avoid eval() in modern code anyway.
- 6.Always generate source maps in production. They let DevTools show original formatted source while the browser executes minified code. Most build tools do this automatically; ensure your hosting serves source maps with appropriate Cache-Control headers.
Frequently Asked Questions
Related Tools
HTML Minifier
Compress and minify HTML code online to reduce file size. Remove whitespace, comments, and redundant attributes for faster loading.
CSS Minifier
Compress and minify CSS code online to reduce file size. Remove whitespace, comments, and shorten selectors for faster page loads.
JSON Minifier
Compress and minify JSON data online by removing whitespace and formatting. Free JSON minifier for smaller payload sizes.
JavaScript Beautifier
Format and indent JavaScript code online for improved readability. Free JS beautifier with auto-indentation and clean output.
Image Compressor
Compress and reduce image file size online while maintaining quality. Free image compressor for JPG, PNG, and WebP optimization.