JavaScript Minifier

Quick answer: JavaScript Minifier is a free online tool that lets you remove comments and redundant whitespace from JavaScript while respecting strings, template literals, and regex. Byte-saved summary included. It works instantly with no signup or download — everything runs privately in your browser.

Remove comments and redundant whitespace from JavaScript while respecting strings, template literals, and regex. Byte-saved summary included. Free, no signup, local.

What is the JavaScript Minifier?

JavaScript minification shrinks scripts by removing comments and collapsing whitespace that the engine ignores — while carefully preserving the characters programs actually depend on. This JavaScript minifier online uses a conservative state machine that understands string literals, template literals with ${} expressions, and regular expressions, so aggressive whitespace removal never corrupts your code.

Correctness details matter in JS: a // inside a string is text, not a comment; a / can start a regex or be division; newlines inside template literals are significant. The minifier tracks all of these states as it scans, removing only true comments and safe whitespace, then reports bytes saved in a trailing comment.

This is a whitespace-and-comment minifier, not a full optimizer — it will not rename variables like Terser or esbuild. That restraint is the point: the output stays readable enough to debug and is safe for quick one-off shrinking. Everything runs locally in your browser with no signup.

Think of this tool as the safe middle ground: stronger than hand-deleting comments, gentler than a full optimizer. It is ideal for scripts you paste into tag managers, CMS custom-code fields, and third-party widgets — places with no build pipeline where you still want smaller payloads. For bundled applications, keep Terser or esbuild in the pipeline and use this for everything outside it.

How to use the JavaScript Minifier

  1. Paste your JavaScript source into the input box.
  2. Click Minify JS to strip comments and collapse safe whitespace.
  3. Copy the output or download it as a .js file.
  4. Check the trailing comment for bytes and percentage saved.
  5. Test the minified file in the browser before deploying; keep the original for development.

JavaScript Minifier use cases

Shrinking embed scripts

Widgets, bookmarklets, and third-party embeds load on other people’s pages — every byte is borrowed. Minify before distributing so hosts pay the smallest possible cost.

Optimizing inline scripts

Small inline scripts in HTML cannot be cached separately, so their size hits every page view. Minifying them trims repeat payload directly.

Preparing code snippets for sharing

Pasting a compact version of a utility function into docs, gists, or chat keeps it readable in one screen while remaining copy-paste runnable.

Quick wins without a build step

Not every project has a bundler. For static sites and prototypes, this tool gives you most of minification’s benefit with zero configuration.

Tips

  • For production bundles, a real optimizer (Terser, esbuild) renames variables too — use this tool for quick safe shrinking.
  • Always test minified output; even conservative minifiers deserve a smoke test before deploy.
  • Keep license comments separately if your dependencies require attribution notices to be preserved.
  • Combine with gzip/brotli on the server for the biggest total reduction.

Frequently asked questions

Will minification break my JavaScript?
This minifier is conservative: it tracks strings, template literals (including ${} expressions), and regex literals while scanning, removing only genuine comments and safe whitespace. The logic of your code is never rewritten. Still, smoke-test the output before deploying. The output has also been syntax-checked in testing, but your own smoke test in a real browser remains the gold standard before deploy.
Does it rename variables like Terser does?
No. It removes comments and whitespace but keeps all identifiers intact, so the output stays debuggable. For maximum compression with mangling, use Terser or esbuild in your build pipeline. That readability is a feature for quick jobs — you can still scan the output and recognize your own code.
How are template literals handled?
Template literals are passed through byte-for-byte, including newlines and ${} expressions, because their whitespace can be significant to the program's output. This caution extends to tagged templates and nested expressions, which are preserved exactly as written. Even deeply nested expressions inside template placeholders are preserved character-for-character.
What about regular expressions containing slashes?
The scanner distinguishes regex literals from division using context, and escaped slashes inside character classes are handled — regexes survive intact. Division operators are likewise left alone, so arithmetic expressions keep working exactly as before. You can confirm this by testing the minified output — every pattern behaves identically.
How much smaller will my JS get?
Comment-heavy development code often shrinks 20–40%. Dense production-style code saves less. The trailing comment on every output shows exact bytes and percentage. The summary comment at the end of every output tells you the precise saving, so you can judge whether it was worth it.
Is my code uploaded to a server?
No. Minification runs entirely in your browser. Proprietary source code never leaves your device, and there is no signup. Client-side business logic and API keys in config can be pasted without exposing intellectual property. This makes the tool safe for proprietary algorithms and unreleased product code.
Can I minify TypeScript with this?
No — strip types first with the TypeScript compiler, then minify the resulting JavaScript here. The playground and most editors compile to JavaScript in one step, giving you clean input for this minifier. The TypeScript playground exports clean JavaScript ready for pasting here.
Does it protect 'use strict' directives?
Yes. String literals — including 'use strict' — are extracted before any processing and restored verbatim, so directives keep working exactly as written. Module-level strict mode from import/export syntax is unaffected too, since the minifier never alters statement structure. Your code keeps the same strict-mode semantics after minification as before.
Could removing newlines break my code via ASI?
Newlines collapse to single spaces, never to nothing, so automatic semicolon insertion behaves the same as in your source. Statements stay separated; the engine sees an equivalent token stream. In short: if it ran before minification, it runs after — the transformation is whitespace-only by design.
Can I minify ES modules with import/export?
Yes. Import and export statements are ordinary syntax to this minifier and pass through unchanged. It does not bundle or resolve modules — for that you need a bundler. Just remember that browsers require type=module for import syntax regardless of whether the file is minified.