Skip to content

JavaScript Minifier

Strip comments and unnecessary whitespace from JavaScript to reduce file size.

Runs in your browserFree, no sign-up

Settings

Results update automatically as you type.

Minified JavaScript

function greet(name){return `Hello,${name}!`;}

Savings

Before
70 chars
After
46 chars
Saved
34%

Good to know. This is a lightweight whitespace and comment minifier. For production builds use a real bundler such as esbuild, SWC or Terser, which also rename variables and remove dead code.

About the JavaScript Minifier

This JavaScript minifier removes block and line comments, trims every line, drops blank lines and closes up the whitespace around braces, semicolons and commas. It is a lightweight, conservative pass rather than a compiler: nothing is renamed, nothing is inlined and no dead code is eliminated, which keeps the output readable enough to debug while still cutting a useful slice off the file size. You see the character count before and after along with the percentage saved. Because the whole thing runs in your browser, proprietary code never leaves your machine — a meaningful difference from tools that post your source to a server for processing.

How to use the JavaScript Minifier

  1. 1

    Paste your JavaScript into the JavaScript box.

  2. 2

    The minified output updates as you type; there are no settings to adjust.

  3. 3

    Read the Savings panel for the before and after sizes and the percentage removed.

  4. 4

    Copy the result or download it as script.min.js.

  5. 5

    Read the 'Good to know' panel, which explains where a real bundler will do considerably better.

What people use it for

Trimming a standalone script

An analytics snippet, a cookie banner or a small widget dropped into a page has no build pipeline. A whitespace pass is the pragmatic way to shrink it.

Stripping developer comments before publishing

Ticket numbers, TODO notes and half-finished ideas in comments are visible to anyone who opens the file in devtools. Minifying removes them in one step.

Pasting code where length is limited

Tag managers, bookmarklets and CMS script fields often impose a character cap, and removing comments and indentation is usually enough to fit inside it.

Whitespace minification versus what a real minifier does

Terser, esbuild and SWC parse your code into an abstract syntax tree and rewrite it. That unlocks transformations impossible with text manipulation. Mangling renames local variables and function parameters to single letters, which is safe because the tool knows the scope of every binding. Dead code elimination removes branches that can never run, such as the body of a condition that is always false. Tree shaking drops exported functions no module imports. Constant folding evaluates expressions like 60 times 60 times 24 at build time. On a typical application bundle that combination is worth far more than whitespace removal alone — often 30 to 60 per cent against perhaps 10 to 20. The trade-off is that AST-based tools must fully understand your syntax, so they need to keep pace with new language features, whereas a text pass does not care what it is reading. Use this tool for small standalone files and a proper bundler for anything you build.

The syntax edge cases a text-based pass has to respect

Stripping comments with regular expressions is harder than it looks, because a double slash is not always a comment. It appears inside string literals, inside a URL such as one beginning https colon slash slash, and inside regular expression literals that match slashes. This minifier requires the character before a line comment not to be a quote, backtick, colon or backslash, which handles the common cases, but it is not a parser, so unusual code can still be mangled — check the output before shipping it. The other hazard is automatic semicolon insertion. JavaScript inserts semicolons at line breaks under a specific set of rules, so joining lines that relied on that behaviour can change meaning, and a line starting with an opening bracket, a slash, a plus or a minus can be silently glued onto the previous statement. Writing explicit semicolons removes the risk entirely, which is one practical argument for the semicolon style in code you intend to minify this way.

Tips

  • Run your test suite against the minified file before deploying it, not only against the source.
  • Serve JavaScript with brotli or gzip enabled; compression usually saves more than minification does on its own.
  • If the output looks broken, suspect a regular expression literal or a URL inside a string that the comment pass caught by mistake.

Frequently asked questions

Does this mangle variable names?
No. It only removes comments and whitespace, which is safe but produces larger output than a full minifier like Terser.
Is my code sent anywhere?
No. Everything happens locally in your browser, so proprietary code stays on your machine.
Why not just rely on gzip?
Compression already removes much of the redundancy, but minifying first typically shaves another 5-15% off the transferred size.

Looking for something else? Browse all developer tools or see every tool.