πŸ“¦

JavaScript Minifier

βœ“ Free & no signup πŸ”’ Runs 100% in your browser Updated 2026-11-25 Website Management Tools

JavaScript ships as text, and text ships with padding: comments explaining old bugs, indentation marking nesting, line breaks between statements, and blank lines separating sections. None of it executes. A minifier deletes the padding while leaving the program's behavior untouched, and this tool performs that pass live in your browser, with the before and after byte counts shown beside the output so the saving is a number you can put in a commit message.

Two transformations are applied. Comments are removed, including line comments and block comments. Whitespace between tokens that carries no meaning, such as indentation, line breaks, and runs of spaces, is collapsed. Strings are recognized before either pass runs, so a comment-like sequence inside a quoted string survives intact, and a space inside a string is never touched. Operators, identifiers, numbers, and punctuation are left exactly as written: no renaming, no reordering, no semantic rewriting of any kind.

The tool runs locally; scripts containing business logic, API keys, or customer-handling code never leave your device. It is free, requires no signup, and works on mobile.

Before and After: Realistic Numbers

Savings depend on how the source was written. A commented, well-indented script saves the most; output from a build pipeline that already strips whitespace saves little. Representative examples:

ScriptBeforeAfterSaved
Hand-written utility library, comments and 2-space indent45,000 bytes28,000 bytes38 percent
Widget script with license header and dense comments12,600 bytes8,100 bytes36 percent
Already compact bundle, minimal comments88,000 bytes82,300 bytes6 percent

The illustrative 45,000-to-28,000-byte row is the honest middle case: a source file written for humans, with a comment on most functions, typically loses about a third of its bytes, and comments plus indentation account for nearly all of it. The third row shows the ceiling of the technique: if the input is already whitespace-light, a whitespace-and-comment minifier has little left to take, which is expected rather than a defect.

An honest caveat about what real production minifiers do beyond this: tools like Terser also rename local variables to one or two characters, fold constants, drop dead code, and rewrite expressions into shorter equivalents. Variable renaming alone often saves another 15 to 25 percent on unminified code, and those transformations require a full parser plus a tested build pipeline, because a wrong rename breaks the program. This tool deliberately performs only the provably safe subset: comments and whitespace out, everything else untouched, so the output always behaves identically to the input.

How Strings and Comments Are Protected

The parser that drives the minifier classifies every character into three worlds: inside a string, inside a comment, or in code. Minification decisions apply only in the code world. A quoted string containing two slashes in a row, which looks exactly like a line comment, stays whole because the string classification wins. A string containing newlines or multiple spaces keeps them, since spaces inside strings are data, not padding. Comments, conversely, are removed entirely wherever they legally occur, including comment blocks between statements and trailing line comments after code.

Input elementTreatmentReason
Line and block commentsRemovedNo effect on execution
Indentation and line breaks between tokensRemoved or collapsedWhitespace between tokens is meaningless
Spaces inside string literalsPreserved exactlyString content is data
Comment look-alikes inside stringsPreservedThe string context outranks the pattern
Identifiers and operatorsPreserved exactlyNo renaming or rewriting

One whitespace subtlety deserves its own mention: a line break between two tokens is not always meaningless, because JavaScript's automatic semicolon insertion rules make some line breaks significant. The minifier only removes line breaks in positions where removing them cannot merge two statements, so code that relies on standard statement structure minifies safely. Code written with deliberately omitted semicolons in risky positions can behave differently when minified by any tool; the reliable practice is to include semicolons in source that will be minified.

How to Use the Minifier (Step by Step)

  1. Paste the script you want to compact. Minification runs live, and the byte savings appear with the result.
  2. Check for comments you need to keep, especially license headers, which are removed like all comments. If attribution requires one, paste a single header comment back at the top of the output.
  3. Copy the minified script into your deployment artifact or inline script tag.
  4. Keep the readable original in source control and re-minify at each deploy; never edit the minified file by hand.

The Deployment Workflow and Source of Truth

The pattern that avoids every classic minification accident is two versions: a formatted master that humans edit and a minified artifact that machines deploy. Hand-editing minified JavaScript is where bugs breed, because a missing comma in a long unbroken line is nearly invisible during review and a mistyped identifier breaks at runtime rather than in the diff. If you receive minified code that needs a change, run it through the paired beautifier first, edit the readable version, and minify again.

License compliance is the one place where minification and legal requirements meet. Most open-source licenses require keeping copyright and license notices with the code. Since this tool removes all comments, re-add the required header to the top of the minified output as a single comment line, which costs bytes only once per file, or maintain a separate attribution file as many build tools do.

Minification, Compression, and What Stacks

Minification is the first layer of a two-layer pipeline. Server compression, gzip or Brotli, is the second, typically removing another 70 to 80 percent of whatever remains on the wire. They stack because compression works on repetitive bytes and minified code is repetitive in a different way than formatted code. The two layers together are why a 45,000-byte source file might reach a visitor as roughly 6,000 bytes of transfer: about 17,000 bytes removed by minification and the remainder compressed by the server.

Tips and Best Practices

  • Minify from a readable master at deploy time, and never edit minified output directly.
  • Include semicolons explicitly in scripts destined for minification; do not rely on automatic insertion in risky positions.
  • Re-add license headers to minified output when a library's license requires the notice to ship with the code.
  • Test the minified script in a staging environment before shipping; behavior should be identical, and a smoke test proves it.
  • Use the byte report to audit whether a deployed script was actually minified; large savings mean it was not.
  • Pair with server compression and caching headers for the full performance effect; minification is one layer of three.

Frequently Asked Questions

How much smaller does JavaScript get after minification?
Typically 6 to 38 percent, depending on the source. A commented, well-indented 45,000-byte script might drop to about 28,000 bytes, a 38 percent saving, while an already-compact bundle might shrink only 6 percent. Comments and indentation account for nearly all of it. The tool reports exact before and after bytes for your input, and server-side gzip or Brotli typically removes another 70 to 80 percent on top of that during transfer.
Does minification change what my JavaScript does?
This tool's transformations are provably behavior-neutral: comments are removed, and whitespace between tokens is collapsed, while strings, identifiers, operators, and numbers are untouched. No variables are renamed and no statements are reordered. One practice matters: keep explicit semicolons in source code, because line breaks that relied on automatic semicolon insertion can become risky when whitespace is stripped by any minifier. Well-structured code with semicolons minifies safely and behaves identically.
Why do real minifiers also rename variables?
Because identifier length is a large share of bytes in real code, and local variable names have no meaning outside their scope, so renaming totalSum to a single letter is safe and saves characters everywhere the name appears. It typically saves another 15 to 25 percent beyond whitespace removal. Renaming requires a full parser to know which names are local and which are external, plus a tested build pipeline to catch mistakes, which is why it belongs in tools like Terser rather than a quick browser tool.
Will minification break strings that contain comment characters?
No. The minifier classifies every character as inside a string, inside a comment, or in code, and transformations apply only to code. A string containing two slashes in a row, which resembles a line comment, stays whole because the string context takes priority. Spaces and line breaks inside strings are also preserved exactly, since string content is data. Only actual comments, outside any string, are removed.
Should I keep license headers when minifying JavaScript?
Yes, when the license requires it, and most open-source licenses do. All comments are removed during minification, including headers, so after minifying, paste the required copyright and license notice back as a single comment at the top of the output, or maintain a separate attribution file as many build tools do. The cost is bytes only once per file, and keeping the notice is a legal requirement for libraries under MIT, Apache, and similar licenses.
Can I edit a JavaScript file after minifying it?
Not sensibly, and you should not try. Minified code has no indentation, no meaningful names in some places, and no comments to orient you, so a one-character edit is easy to get wrong and nearly impossible to review. The correct workflow is to keep the formatted original as the master copy in source control, make changes there, and re-minify at deploy time. If you only have minified code, run it through the paired beautifier first, edit, then minify again.

Related Tools