JavaScript Minifier & Beautifier

Paste your JavaScript to minify or beautify it instantly. 100% client-side — your code never leaves your browser.

Input JavaScript
Output
Paste JavaScript above to minify or beautify it.

How to Use the JavaScript Minifier

  1. Paste your JavaScript into the input area on the left (or top on mobile).
  2. Choose a mode — Minify (default) compresses your JS, Beautify formats it with indentation.
  3. View the result instantly — the output panel updates as you type.
  4. Copy or download — copy to clipboard or save as output.js.

What This JavaScript Minifier Does

This free online JavaScript minifier uses a carefully designed parser to compress your JavaScript without breaking it. It handles the core challenge of JS minification: distinguishing comment-like sequences that appear inside strings and regular expressions from actual comments. The result is a compact, functional script ready for production use.

Minification Features

  • Single-line comment removal — removes // comment lines while preserving string contents
  • Block comment removal — strips /* ... */ comments safely
  • Whitespace collapse — removes unnecessary spaces, tabs, and newlines
  • String preservation — content inside single-quoted, double-quoted, and template literal strings is never modified
  • Operator spacing — removes redundant spaces around operators where safe

Beautify Features

  • Block indentation — indents code inside { } blocks consistently
  • Statement newlines — puts each statement on its own line
  • Configurable indent — choose 2-space or 4-space indentation

Why Minify JavaScript?

JavaScript files are often the largest resources on a web page and are render-blocking by default. Every extra kilobyte the browser must download before executing your scripts delays the page load. For users on mobile data connections or in regions with slower networks, this can mean the difference between a page that loads in two seconds and one that takes five or more. Google's Core Web Vitals — particularly Time to Interactive (TTI) and Total Blocking Time (TBT) — are directly influenced by JavaScript file size.

Minification reduces JS file size by removing characters that the JavaScript engine never sees anyway: comments are stripped by the tokenizer, whitespace is irrelevant to the parser, and newlines are only required where the automatic semicolon insertion rules require them. A typical unminified script of 50 KB can be reduced to 30-35 KB by minification alone. Combined with gzip or Brotli server compression, the same file might transfer as only 12-15 KB.

Limitations of Browser-Based Minification

This tool uses a string-processing approach to minification. It handles comments, strings, and template literals correctly for most real-world JavaScript. However, it does not perform advanced optimizations that dedicated tools like Terser and esbuild provide: variable name shortening, dead code elimination, inlining of constants, or module bundling. For production builds, use your framework's built-in build process (Vite, webpack, or Rollup with the appropriate plugins). This tool is ideal for quickly minifying standalone scripts, bookmarklets, or third-party code you want to embed.

JavaScript Source Maps

When minifying JavaScript for production, always generate source maps if your deployment process supports them. Source maps are separate .map files that map minified code back to the original source, making it possible to debug production errors using your original variable names and line numbers. Browser DevTools can automatically use source maps when they are linked from the minified file via a //# sourceMappingURL= comment. This tool does not generate source maps — for that, use a proper build tool. Once minified, you can compare versions using our Diff Checker.

Frequently Asked Questions

JavaScript minification removes comments, whitespace, and newlines from JS source code without changing how it executes. The result is a smaller file that downloads faster. In production, minified JS is the standard — it can reduce file sizes by 30-60% before any server-side compression is applied.
No. This JavaScript minifier processes your code entirely in your browser. Your code never leaves your device. There is no server, no logging, and no data collection.
Minification removes whitespace and comments to reduce file size while keeping the code functionally identical and variable names unchanged. Obfuscation goes further — it renames variables to meaningless single characters and intentionally makes code difficult to reverse-engineer. This tool minifies but does not obfuscate.
Yes — use the Beautify mode on this tool to re-add indentation and newlines to minified JavaScript. However, beautification cannot recover removed comments or original variable names if the code was also obfuscated. Source maps (.map files) are the proper solution for debugging minified production code.
For production builds, use a proper build tool: Vite, webpack, Rollup, or esbuild all include JavaScript minification. These tools also support tree-shaking, code splitting, and source maps. This browser tool is ideal for quick one-off minification without setting up a build pipeline.