Developer Utilities · Free tool
JavaScript Minifier
Compress JS code by removing comments and whitespace instantly in your browser—free, no-sign-up tool for quick size reduction before production.
Quick whitespace/comment minifier — strips // … and /* … */ comments, collapses spaces, trims around operators. For production-grade minification (variable mangling, dead-code elimination, AST-aware passes), use terser or esbuild. This tool typically saves 30–60% on hand-written code; minifiers like terser hit 70–85%.
Advertisement
What it does
Quick text-based JavaScript minifier. Paste a snippet, get back a minified version with whitespace collapsed, comments stripped (both // line and /* block */), and spaces around operators trimmed. Useful for quick one-liners (a function or snippet you want to paste into a constrained context), email and chat embedding where line breaks confuse the receiver, bookmarklet creation (everything has to fit in a single javascript: URL), and quick eyeballing of code size before vs. after minification.
This is textual minification only. For real production minification you want terser (the de-facto standard) or esbuild (faster, integrates with modern build tools). Those do AST-aware optimizations: variable name mangling (renaming userPreferences to a), dead- code elimination (removing if (false) {...}branches), constant folding ( 1+2 → 3 at compile time), property mangling, and tree-shaking unused exports. Textual minification (whitespace + comments) typically saves 30-60%; terser on the same input typically saves 70-85%.
Use this tool when you want a quick one-shot minification without setting up a build pipeline. For your project’s actual production bundle, use Vite/Webpack/Rollup/Parcel which all integrate terser by default.
Embed this tool on your siteShow snippetHide
Paste this snippet into any page. Loads on-demand (lazy), no tracking scripts, and sized to most dashboards. Replace the height to fit your layout.
<iframe src="https://freetoolarena.com/embed/javascript-minifier" width="100%" height="720" frameborder="0" loading="lazy" title="JavaScript Minifier" style="border:1px solid #e2e8f0;border-radius:12px;max-width:720px;"></iframe>How to use it
- Paste your JavaScript code into the input.
- The minified version regenerates live as you type, with size before/after and savings percentage shown.
- Click Copy to put the minified version on your clipboard.
- Test the minified output in a browser console before deploying — textual minification can break code that depends on whitespace (rare but happens with template literals, regex literals, or unusual spacing in object methods).
- For production builds, use terser or esbuild via your build tool, not this manual approach.
When to use this tool
- Creating a bookmarklet — everything has to fit in javascript:URL within URL-length limits.
- Pasting a one-off function into a chat or email where line breaks would mangle it.
- Quick size eyeballing — see how much your handwritten code shrinks with whitespace removal.
- Inline scripts in HTML attributes (onclick="...") that need to fit in one line.
When not to use it
- Production website builds — use terser/esbuild via Vite/Webpack/Rollup. They produce 2× smaller output than text-only minification.
- Code with template literals or regex literals where intra-string whitespace matters — text-only minification can corrupt them. AST-based minifiers handle correctly.
- TypeScript or JSX — those need transpilation first; this tool is JavaScript-only.
- Source-mapped output for debugging — text minification doesn't produce source maps. Real build tools generate maps that let you debug minified code in the original form.
Common use cases
- Onboarding a colleague who needs the same calculation/conversion
- Verifying a number or output before passing it on
- Quick use during a typical workday
- Pre-decision sanity-check on inputs and outputs
Frequently asked questions
- Why use terser instead?
- terser does AST-aware minification: variable mangling (long names → 1-2 letters), dead-code elimination, constant folding, property name mangling, and more. This tool does textual minification only — typically saves 30-60%; terser hits 70-85% on the same input. For production, always use terser via your build tool.
- Will the minified code still work?
- Almost always yes for well-formed code. Edge cases that can break: (1) template literals where intra-string whitespace was meaningful (rare), (2) regex literals followed by `/` (rare), (3) ASI-dependent code with no semicolons in unusual places (very rare). Always test minified output before deploying.
- What about source maps?
- This tool doesn't generate source maps. For debugging-friendly minification, use terser with `sourceMap: true` — it produces a .map file that lets browsers show original line numbers when errors occur in minified code.
- Can I minify CSS or HTML with this?
- JS-only. CSS minifiers and HTML minifiers exist as separate tools (cssnano, html-minifier-terser). The minification rules differ — CSS allows whitespace minification but has different escape rules; HTML has tag/attribute rules.
- What's a bookmarklet?
- A small JavaScript snippet stored as a bookmark (URL prefix `javascript:`). When you click the bookmark, the script runs on the current page. Useful for one-click utilities (highlight all links, save to read-later, fill a form). Bookmarklets must fit in one URL — 2,000-32,000 characters depending on browser, so minification matters here.
- Will TypeScript or modern JS features break?
- TypeScript needs transpilation to JS first (this tool doesn't do that). Modern JS features (optional chaining, nullish coalescing, async/await, top-level await, etc.) generally minify fine — text-based minification doesn't care about feature semantics, just whitespace and comments.
Advertisement
Learn more
Guides about this topic
- Using Our Tools · GuideHow to generate QR codesMake QR codes for URLs, WiFi, vCard, or text. Learn error correction and sizing, then generate your QR code online free with no sign-up in seconds.
- Using Our Tools · GuideHow to create a strong passwordGenerate a strong password instantly online for free. Build high-entropy passphrases following NIST 2026 rules with no download needed.
- Developers & Technical · GuideHow to encode and decode Base64Understand the 3-to-4 mechanic and 33% overhead for standard, URL-safe, and MIME Base64. Free online reference to avoid common mistakes, no download needed.
- Design & Media · GuideHow to choose a color paletteBuild accessible color palettes using HSL theory, monochromatic to triadic schemes, WCAG contrast checks, and dark mode tips. Free, no-download guide.
- Developers & Technical · GuideHow to use JWT tokens securelyImplement secure JWT authentication by choosing RS256, setting expiration, using httpOnly cookies, and preventing 'alg: none' attacks in your browser for free.
- Design & Media · GuideHow to design a faviconCreate favicons that render perfectly from 16×16 to 512×512 with dark mode support. Learn the right HTML tags and web manifest setup free online.
Explore more developer utilities tools
- Port Number LookupSearch over 140 well-known TCP and UDP ports by number or service name. Free online reference tool with no sign-up, covering web, mail, DNS, and more.
- Test Credit Card NumbersReference table of canonical test card numbers from Stripe, Adyen, and Braintree sandbox docs. Plus Luhn validator + network detector.
- IPv6 Expander & ShortenerFormat IPv6 addresses to canonical form, handling zone IDs and prefixes, instantly online—free tool with no registration required.
- Htpasswd GeneratorCreate .htpasswd lines for Apache or nginx basic auth with browser-only SHA hashing instantly. Includes config snippets and a free online tool with no registration.
- Chmod CalculatorCalculate Unix file permissions: octal (755, 644) ↔ symbolic (rwxr-xr-x) ↔ rwx checkboxes. Covers setuid, setgid, sticky bit. With presets.
- Excel Formula ExplainerPaste any formula and get a plain-English breakdown of 60+ functions online free—no sign-up required, in your browser.