JavaScript Minifier — Free Minify JS Online

JavaScript is often the largest single resource a page downloads, and unlike images it must be parsed and executed before the page becomes interactive. Comments, descriptive variable names, and generous formatting make code maintainable — and make the downloaded file far bigger than it needs to be.

A minifier bridges that gap: it strips comments, collapses whitespace, and removes every byte that does not change what the code does. The result is functionally identical JavaScript in a fraction of the size, which means faster downloads, faster parsing, and snappier pages — especially on mobile networks.

This free JavaScript minifier takes the safe approach: it removes comments and redundant whitespace while carefully preserving strings, template literals, and regular expressions, whose contents must never be touched. It shows exact before/after byte counts so you can measure the win. Note that it is a whitespace/comment minifier, not a full optimizer like Terser — it will not rename variables, so the output is guaranteed to behave like the input.

How to use the JavaScript minifier

  1. Paste your JavaScript into the input area — a function or a whole file.
  2. Review the minified output, which updates live as you type.
  3. Check the savings — before/after bytes and the percentage reduction.
  4. Copy the result into your production bundle or .min.js file.
  5. Test before shipping. Run the minified code in a staging environment to confirm identical behavior.

Key features & benefits

  • Comment stripping. Both // line and /* block */ comments are removed, including documentation blocks.
  • Whitespace collapsing. Newlines and indentation collapse to the minimum spacing the syntax requires.
  • String protection. Single-quoted, double-quoted, and template-literal contents are copied verbatim — "a // not a comment" survives intact.
  • Regex awareness. Regular expression literals are detected so /// is never mistaken for a comment.
  • Behavior-preserving. Because nothing is renamed or restructured, the minified code does exactly what the original did.
  • Instant size report. See precisely how many bytes you saved on every paste.

Using minification safely

Minified code is a deployment artifact. A few habits keep it painless.

Keep source maps for production debugging

When an error occurs in minified code, stack traces point at line 1, column 48291. Generate a source map in your build so you can map errors back to the original source. For quick one-off minification here, keep the original file handy alongside the .min.js version.

Minify as the last step

Run linters, tests, and type checks on the readable source, then minify for release. Minifying test or debug code just to “save space” in development slows everyone down for no benefit. If you are optimizing a full site, minify stylesheets too with our CSS minifier.

Know when you need a real bundler

This tool is ideal for snippets, widgets, and small scripts. For applications with modules and dependencies, a bundler plus Terser or esbuild will also tree-shake dead code and rename variables for deeper savings. If you inline small assets as data URIs, our Base64 encoder/decoder prepares them. When pasting API-heavy scripts, our JSON formatter helps inspect the data they consume.

Frequently asked questions

Is this as good as Terser or UglifyJS?

Not for maximum compression — those tools also shorten variable names, drop dead code, and fold constants, typically saving another 10–20% beyond whitespace removal. This tool deliberately skips those transforms so the output is provably behavior-identical, which makes it perfect for quick jobs and for code you cannot easily re-test.

Will it break my template literals?

No. Template literals (including ${...} interpolations and multi-line strings) are recognized and preserved exactly. Only the code around them is compressed.

What about “use strict” and semicolons?

Directives like "use strict" are strings and are preserved. The minifier keeps semicolons where they are required and only removes whitespace, so automatic semicolon insertion hazards are not introduced.

Can I minify TypeScript with this?

Not directly — type annotations are not valid JavaScript and would confuse the parser. Compile TypeScript to JavaScript first, then minify the output. The same applies to JSX: transform it before pasting.

Why is my savings percentage low?

Already-compact code (bundler output, for example) has little whitespace left to remove — most of its remaining bulk is identifier names, which this safe minifier intentionally keeps. For deeper cuts on such files, a renaming optimizer like Terser is the right next step.

How It Works: Under the Hood

Minification works in passes. First pass — lexical cleanup: the tool parses the code into an AST (abstract syntax tree) rather than doing dumb text replacement, then strips comments, collapses whitespace, and removes unnecessary semicolons and trailing commas. Second pass — mangling: local variable and function names are renamed to the shortest available identifiers (a, b, c… then aa, ab). Globals and exported names are left intact so external code keeps working. Third pass — compression: constant expressions are evaluated (2 * 60 becomes 120), true/false become !0/!1, undefined becomes void 0, and dead code after return statements is eliminated.

The result is typically 30–60% smaller than the source. The tool never executes your code — all transformations are provably semantics-preserving rewrites on the AST, which is why minified output behaves identically to the original.

Real-World Use Cases

  • Production deploys: build pipelines minify every JS bundle before upload — a 400 KB app script becomes ~150 KB, cutting parse time on mid-range phones noticeably.
  • Embeddable widgets: chat widgets and analytics snippets must be tiny since they load on other people’s pages. Minification plus gzip gets a 60 KB widget under 20 KB.
  • Email-adjacent scripts: constrained environments (some CMS text widgets, bookmarklets) have hard size limits where every byte counts.
  • CDN cost control: high-traffic sites pay per GB transferred. Minifying a 1 MB library served 10M times/month saves real money.
  • Quick one-off optimization: no build setup? Paste a legacy jQuery plugin here, minify, deploy — instant win without touching the toolchain.

Advanced Tips

  • Always pair with gzip/brotli. Minification and compression multiply: minify first (removes redundancy humans added), then let gzip remove the remaining statistical redundancy. Together they often reach 70–80% total reduction.
  • Keep a source map for production. Minified code is undebuggable. Generate a .map file alongside — browsers use it to show you original code in devtools while users get the tiny file.
  • Don’t minify already-minified libraries. Running jQuery.min.js through a minifier again saves ~0% and risks introducing bugs. Minify only your own unminified code.
  • Check for eval and with. Code using eval() or with blocks defeats name mangling (the minifier can’t know which names are referenced dynamically). Refactor those out first for maximum savings.

Common Mistakes to Avoid

  • Deploying minified code as the only copy. Always keep the original source in version control. Debugging or updating minified code directly is a nightmare you’ll regret.
  • Minifying ES modules and serving as classic scripts. import/export syntax requires type="module". Minification doesn’t change module semantics — your script tag must match.
  • Forgetting to test after minifying. 99% of the time output is identical, but aggressive compress options can occasionally break edge cases (e.g., relying on Function.name). Smoke-test the minified bundle.
  • Minifying during development. Dev builds should be unminified with full names and comments. Minify only in the production build step.

Minify Last, Bundle First: A Safe Minification Habit

Minify production builds last, never your only copy of the code — keep the original source for debugging and minify the shipped copy. This minifier is a safe whitespace/comment minifier, not a full optimizer like Terser or UglifyJS: it preserves behavior without rewriting logic. When scripts ship inside JSON configs, validate those first with the JSON formatter. For quick encode work on payloads, the URL encoder decoder handles the fiddly characters.