UtilityKit

500+ fast, free tools. Most run in your browser only; Image & PDF tools upload files to the backend when you run them.

JavaScript Minifier

Minify JavaScript by removing comments, trimming whitespace, and outputting cleaner code instantly in your browser.

About JavaScript Minifier

JavaScript Minifier compresses JS source code by removing comments, stripping whitespace, shortening local variable names, and eliminating dead code branches — all without changing what the script does at runtime. Paste your JavaScript and the tool returns a minified version along with a before/after size comparison. Minification is the single most impactful step you can take to reduce JS payload: scripts that drive interactive behaviour must be downloaded and parsed before the browser can execute them, and every kilobyte saved translates directly to faster interaction readiness. A typical utility script compresses 30–50%; large application bundles with verbose variable names and formatted code can compress 60% or more.

Why use JavaScript Minifier

Reduces Parse and Execution Time

The browser must parse every byte of JavaScript before it can build the call graph. Smaller scripts parse faster, unblocking the main thread sooner and improving Total Blocking Time — one of Google's Core Web Vitals metrics.

Variable Name Shortening

Local variables with descriptive names like userAuthenticationToken become single characters like a in the minified output. This alone can shrink variable-heavy utility code by 20–30% beyond whitespace removal.

Comment Stripping

Block comments, inline comments, and JSDoc annotations are valuable in source but invisible at runtime. Removing them eliminates documentation payload from production scripts without touching the source file.

Handles Modern ES Syntax

Arrow functions, optional chaining (?.), nullish coalescing (??), async/await, destructuring, and private class fields are all handled correctly. The minifier compresses without transpiling.

Works Without a Build Tool

Projects that ship plain JS files without Webpack, Rollup, or esbuild still need minification before production. This tool provides the final compression step with a paste-and-copy workflow.

Precise Byte Savings Shown

The before/after size display lets you measure the exact impact of minification on your specific script and decide whether further optimisations — code splitting, tree-shaking — are worth the effort.

How to use JavaScript Minifier

  1. Paste your JavaScript source code into the left input panel.
  2. The minified output appears instantly in the right panel — no button click required.
  3. Check the size bar to see original size, minified size, and the percentage reduction.
  4. Review the output to confirm the logic is correct, especially if you use global variable names that should not be shortened.
  5. Click Copy to copy the minified JS to your clipboard for direct use.
  6. Click Download to save the output as a .min.js file ready for deployment or CDN upload.

When to use JavaScript Minifier

  • Before deploying a custom JS utility, analytics snippet, or widget to a production website or CDN.
  • When inlining a small JavaScript snippet directly in HTML and needing to keep the <script> block compact.
  • After writing a bookmarklet or userscript that must fit in a browser bookmark URL or be pasted into a console.
  • When a Lighthouse audit reports unused JavaScript or large JS payloads as opportunities and you want to measure the minification contribution.
  • Before embedding a JS snippet in a third-party tag manager like Google Tag Manager where script size affects page load.
  • When distributing a JavaScript library or widget that other developers will load from a CDN — providing a .min.js alongside the source is the standard distribution pattern.

Examples

Utility function with JSDoc comments

Input: /** * Formats a number as a currency string. * @param {number} amount - The amount to format. * @param {string} currency - ISO 4217 currency code. * @returns {string} Formatted currency string. */ function formatCurrency(amount, currency = 'USD') { // Use Intl.NumberFormat for locale-aware formatting const formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: currency, }); return formatter.format(amount); }

Output: function formatCurrency(a,b='USD'){return new Intl.NumberFormat('en-US',{style:'currency',currency:b}).format(a);}

Arrow function with optional chaining

Input: // Get user display name with fallback const getDisplayName = (user) => { // Try full name first, then username, then anonymous const fullName = user?.profile?.fullName; const username = user?.username; return fullName ?? username ?? 'Anonymous'; };

Output: const getDisplayName=a=>a?.profile?.fullName??a?.username??'Anonymous';

Event listener with async fetch

Input: document.getElementById('load-btn').addEventListener('click', async function() { // Show loading state const button = this; button.disabled = true; button.textContent = 'Loading...'; try { const response = await fetch('/api/data'); const data = await response.json(); console.log('Loaded:', data); } catch (error) { console.error('Fetch failed:', error); } finally { button.disabled = false; button.textContent = 'Load Data'; } });

Output: document.getElementById('load-btn').addEventListener('click',async function(){const a=this;a.disabled=true;a.textContent='Loading...';try{const b=await fetch('/api/data');const c=await b.json();console.log('Loaded:',c);}catch(d){console.error('Fetch failed:',d);}finally{a.disabled=false;a.textContent='Load Data';}});

Tips

  • Never commit minified JS to version control as your primary source — keep the readable original and generate the .min.js as a build artefact.
  • If your minified output throws a ReferenceError, check for implicit globals or eval() calls that relied on a local variable name that was shortened.
  • Bookmarklets must start with javascript: and fit on one line — run your bookmarklet code through this minifier first, then prepend the protocol.
  • For inline analytics or tag manager snippets, minification + manual gzip size estimation tells you the real network cost — use the percentage saved to prioritise further cuts.
  • When minifying third-party code for inspection or embedding, check its license first — some open-source licenses require retaining the original copyright comment block.

Frequently Asked Questions

Will minification break my JavaScript logic?
Minification only removes whitespace and comments and renames local variables to shorter identifiers. The resulting code executes identically. Global variable names, exported identifiers, and property names accessed via string keys are preserved.
Does the minifier support modern JavaScript like optional chaining and async/await?
Yes. ES2022 syntax including optional chaining (?.), nullish coalescing (??), logical assignment (&&=, ||=, ??=), async generators, and top-level await is handled correctly without transpilation to older syntax.
What is the difference between minification and obfuscation?
Minification reduces file size by removing non-essential characters and shortening local names. Obfuscation intentionally makes code hard to understand by scrambling identifiers and inserting misleading patterns. This tool minifies; it does not obfuscate.
Will eval() or Function() calls cause problems after minification?
Yes — if your code uses eval() with string arguments that reference local variable names, those names may be shortened by the minifier, breaking the eval'd string. Avoid eval(); refactor first, then minify.
Should I minify before or after bundling?
Minify after bundling. Bundlers like Webpack and esbuild can eliminate dead code (tree-shaking) across modules before minifying the result. Minifying individual files first doesn't enable cross-module dead-code elimination.
Can I use source maps with the minified output?
This tool does not generate source maps. If you need source maps for production error tracking via Sentry or similar tools, use a build tool like esbuild or Terser with source map support enabled.
Does the minifier handle strict mode and ES modules?
Yes. 'use strict' declarations are preserved (they are runtime-significant). ES module import/export statements are preserved without transformation so the output can be used directly as a module script.
How does minification interact with gzip compression on the server?
They compound: minification reduces file size by 40–60%, then gzip reduces it a further 60–80%. A 100 KB script might minify to 55 KB and then compress to 15 KB on the wire — a 85% total reduction.

Explore the category

Glossary

Minification
Transformation of JavaScript source code to remove whitespace, comments, and rename local variables to the shortest possible identifiers, reducing file size without changing runtime behaviour.
Tree Shaking
A dead-code elimination technique used by module bundlers that removes exported functions and variables that are never imported by any module in the bundle, reducing total script size.
Total Blocking Time (TBT)
A Core Web Vitals metric measuring how long the main thread is blocked by JavaScript parsing and execution during page load. Smaller, faster-parsing scripts reduce TBT.
Source Map
A .map file that maps positions in minified/bundled output back to their original source locations, enabling browsers and error trackers to display meaningful stack traces from minified production code.
Terser
The de facto standard JavaScript minifier used by Webpack, Vite, and esbuild. It performs whitespace removal, dead code elimination, and identifier shortening, producing the smallest safe output of any current open-source minifier.
Dead Code Elimination
Removal of code that can never be reached or executed — for example, the false branch of if (false) {...} or functions that are defined but never called. Applied by advanced minifiers as a size optimisation.