ShotMark
Skip to Content

JavaScript Minifier

Minify JavaScript by removing whitespace and shortening identifiers.

JavaScript
Minified
Waiting for input

What is JavaScript Minifier?

A JavaScript minifier is a developer tool that strips whitespace, comments, and other non-functional characters from JavaScript source code, then often shortens variable and function names to produce a smaller file that runs identically to the original. The output is byte-for-byte smaller but semantically equivalent, which means browsers download and parse it faster without any change in behavior.

Frontend engineers, build engineers, and library authors use a JavaScript minifier on every production deploy. The same code that ships at 240 KB unminified routinely drops below 80 KB after minification, and shrinks further once gzip or Brotli runs on top.

Why use the JavaScript Minifier

  • Cut bundle size by 50% to 70%. Removing whitespace, comments, and long identifiers typically halves raw JavaScript size before compression and saves another 20% to 30% after gzip.
  • Improve Time to Interactive. Less JavaScript means fewer bytes downloaded and less parse time on low-end mobile CPUs.
  • Lower bandwidth and CDN costs. Every kilobyte trimmed compounds across millions of downloads.
  • Match production parity in staging. Running the same minifier in pre-prod catches edge cases like reserved-word collisions before they hit users.

How to use the JavaScript Minifier

  1. Paste your JavaScript source into the input panel on the left.
  2. Click the Minify button at the top of the panel.
  3. Read the minified output in the right panel. Errors from invalid syntax appear in red above the panels.
  4. Copy the result with the Copy button and paste it into your dist/ folder, CDN upload, or inline <script> tag.

Minification techniques

The tool applies the standard pipeline most production minifiers use, in this order.

PassWhat it removes or rewritesTypical savings
Whitespace removalNewlines, indentation, spaces around operators15-25%
Comment strippingSingle-line //, block /* */, JSDoc5-15%
Identifier manglingRenames locals like userAccountBalance to a20-35%
Dead code eliminationDrops if (false) branches, unreachable return5-15%
Literal foldingCollapses 60 * 60 * 24 to 864001-5%
Boolean shorteningRewrites true to !0, false to !10.5-2%

Identifier mangling only touches names that are safe to rename. Object property names, exported symbols, and anything reached via eval or bracket access (obj["userName"]) are left alone.

Size savings example

Input (218 bytes):

// Calculate the total price including tax function calculateTotal(items, taxRate) { let subtotal = 0; for (const item of items) { subtotal = subtotal + item.price * item.quantity; } return subtotal * (1 + taxRate); }

Minified output (87 bytes):

function calculateTotal(t,a){let l=0;for(const o of t)l=l+o.price*o.quantity;return l*(1+a)}

The example below shows typical savings across input sizes.

InputRaw sizeMinifiedGzippedTotal reduction
Small utility (5 functions)1.2 KB480 B290 B76%
Component library file18 KB6.4 KB2.1 KB88%
Application bundle240 KB78 KB24 KB90%
Vendor bundle (React + deps)410 KB132 KB41 KB90%

Common use cases

  • Production builds for SPAs and SSR apps. A browser-based tool is faster than spinning up a bundler for one-off snippets and patches.
  • Embedded SDKs and tracking pixels. A 2 KB analytics snippet is acceptable as a synchronous <script>. The same code at 8 KB is not.
  • WordPress, Shopify, and Squarespace theme files. CMS editors that limit file size benefit from pre-minified payloads.
  • Inline scripts in HTML email or AMP pages. Email clients strip whitespace inconsistently, so minifying before paste keeps the markup predictable.

Frequently asked questions

Is minified JavaScript reversible?

Whitespace and comment removal cannot be undone, since the information is gone. Identifier mangling is also lossy, because the original variable names are not stored anywhere. A prettifier can re-indent minified code so it is readable, but the names stay as a, b, c. Source maps are the only way to recover the original code.

Does minifying break my code?

Correct minifiers preserve semantics. The common breakage causes are code that depends on Function.prototype.toString, code that accesses properties by mangled names, or code that uses eval on a string that references local variables. If your code does any of these, mark those identifiers as reserved before minifying.

What is the difference between minify and compress?

Minification rewrites the source code itself by removing characters and renaming identifiers, and the output is still valid JavaScript. Compression (gzip, Brotli) wraps the entire byte stream in a binary encoding that the browser must decompress before parsing. The two are complementary, and running both gives roughly 90% total reduction.

Should I minify in development?

No. Minified code is harder to debug, breaks source mapping in some setups, and adds build time. Run the JavaScript minifier only in production builds, and ship source maps so you can still trace errors to readable code.

Will minification obfuscate my code?

Partially. Mangled names make code harder to read, but variable flow and string literals remain visible. For real obfuscation, use a dedicated tool that scrambles control flow, encrypts strings, and adds dead branches. Minification is a side effect, not the goal.

Can I minify ES2020 or newer JavaScript?

Yes. The minifier accepts modern syntax including optional chaining, nullish coalescing, top-level await, and class private fields. Transpile to your target browsers first if you need older support.

  • CSS Minifier - strip whitespace and comments from CSS to shrink stylesheet bundles.
  • HTML Minifier - collapse whitespace and remove comments from HTML markup.
  • SQL Minifier - flatten multi-line SQL into a single line for embedded queries.
  • JavaScript Validator - check JavaScript syntax before you ship the minified bundle.
Like this tool?

ShotMark captures what you do here, in one click.

The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.

Private beta accessFounding pricing lockNo spam ever