JS Minifier

Minify, beautify, and validate JavaScript with compression stats, code analysis, and an optimization report — all local to your browser.

Loading tool…

What JavaScript minification does

Minifying JavaScript is more involved than minifying CSS, because the transformation has to preserve program behaviour exactly. A minifier parses the source into a syntax tree, then re-emits it without whitespace, comments, or unnecessary punctuation, and typically renames local variables to single letters — calculateTotalPrice becomes a inside its own scope.

The renaming is where most of the saving comes from, and it is safe only for names the engine can prove are local. Anything reachable from outside — exported functions, global objects, properties accessed by string — must keep its name. This is also why minified code makes stack traces useless, and why production builds ship source maps: a separate file mapping the compressed output back to your original lines so you can still debug what users are running.

Why we built this tool

Scripts are the heaviest part of most pages and the most expensive to process, since bytes must be downloaded, parsed, compiled, and executed. Cutting them is one of the highest-value performance changes available, particularly on mid-range phones.

The code you are minifying is your product, sometimes before release, and occasionally contains an API endpoint or key that should not be there. Sending it to a stranger's server to save a few kilobytes is a poor bargain. Our minifier runs the whole parse-and-emit cycle in your browser, so your source never leaves the tab, there is no file-size limit, and no copy is retained anywhere. Once the page is loaded it works with the network off.

Tips and common mistakes

  • Always test the minified output before deploying it; minification is where subtle behavioural bugs surface.
  • Code relying on function names at runtime, or on property access by string, can break when names are shortened.
  • Generate and keep source maps so production stack traces remain readable.
  • Never minify code containing API keys as a way of hiding them — anything shipped to a browser is readable.

Open JS Minifier with a link

Assistants and scripts can open JS Minifier with its input already in the link, after the #, which never leaves your device:

  • #text= — the text to work on

Example: https://mygadgets.ink/tools/js-minifier/#text=... · also compressed gz fields and ?url=. How tool links work

Quick start: using JS Minifier

  1. Paste your JavaScript or load the .js file above.
  2. Run the minifier and check the size reduction reported.
  3. Test the minified output in your application before deploying it.
  4. Keep your unminified source in version control — minification is not reversible.
  5. Serve the file with gzip or Brotli compression for a further saving.

Pair it with CSS Minifier and HTML Minifier to trim the whole page.

What minification removes

A JavaScript minifier reduces file size without changing behavior by removing:

  • Comments — documentation the engine ignores.
  • Whitespace and line breaks — all the formatting that aids reading.
  • Unnecessary characters — optional semicolons, redundant braces where syntax allows.

Advanced minifiers also rename local variables to single letters (userAccount becomes a), which saves significant space in code with long, descriptive names. The script runs exactly the same; it is just smaller and unreadable.

Minification is not security

A common misconception: minified code is not protected. Renaming variables makes it harder to read, but anyone can run it back through a formatter and study the logic. Minification is a performance optimization, not a way to hide secrets. Never put API keys, passwords, or sensitive logic in client-side JavaScript expecting minification to conceal them — it will not.

Keep the source, ship the minified

As with CSS, never maintain minified JavaScript by hand. Keep your readable source, edit that, and minify only what you deploy. If a minified script breaks in production, debug against the original — minified stack traces are nearly useless without a source map.

Test after minifying

Aggressive minification occasionally exposes a latent bug — code that relied on a variable name, or on whitespace-sensitive edge cases. Always run your minified bundle once before shipping to confirm it behaves. Reliable minifiers rarely cause this, but a quick check is cheap insurance.

Common uses

  • Speed up page load and time-to-interactive.
  • Reduce bandwidth for scripts.
  • Prepare code for production.

Related Developer Tools

Browse all Developer Tools →