UTILYARD
tools / developer

JavaScript Minifier

Remove comments and whitespace from JavaScript.

⚠ Basic minifier — use a build tool for production code.
INPUT
OUTPUT
output appears here...

About JavaScript Minifier

This tool removes single-line comments, multi-line comments, and unnecessary whitespace from JavaScript source code. It is intended for simple scripts and quick experiments. For production builds, a proper bundler like Vite, Webpack, or esbuild will produce superior results including variable renaming, tree-shaking, and dead code elimination. All processing runs locally in your browser — nothing is uploaded.

FAQ

Is this safe for production use?
This is a basic minifier that removes comments and collapses whitespace. For production builds, use a proper bundler like Vite, Webpack, or esbuild.
What gets removed?
Single-line comments (//), multi-line comments (/* */), and unnecessary whitespace.
Will it break my code?
It should not break well-formed JS, but always test the output. Complex expressions with regex literals may need manual review.

ABOUT THIS TOOL

Paste JavaScript and the tool strips comments, unnecessary whitespace, and line breaks to produce a smaller file that runs identically to the original. Unlike a full production minifier such as Terser, this keeps variable and function names intact rather than renaming them to single letters, so the output stays smaller than the source but remains somewhat readable and easy to debug. It's a quick way to shrink a script before pasting it somewhere space-constrained, checking roughly how much size formatting overhead was adding, or cleaning up a snippet before sharing it, without setting up a bundler like Webpack or esbuild.

HOW TO USE

  1. Paste your JavaScript code into the input box.
  2. Run the minifier to strip comments, whitespace, and line breaks.
  3. Test the minified output to confirm it behaves identically to the original.
  4. Compare file size before and after if you want to see the savings.
  5. Use the compact version for production or embedding; keep your commented source as the file you actually edit.

COMMON USE CASES

  • A developer shipping a small vanilla JS file on a site without a build pipeline like Webpack or esbuild.
  • Someone embedding a script into a CMS widget field or a bookmarklet where every character counts.
  • A developer checking how much of a file's size is comments and formatting versus actual logic.
  • Someone preparing a script for a size-constrained embed or a code golf challenge.
  • A team lead comparing a specific function's minified size against what a full bundler's output roughly corresponds to.

TIPS & COMMON MISTAKES

  • This does safe minification - removing comments and whitespace - but doesn't rename variables or do dead-code elimination the way Terser or esbuild do, so don't expect bundler-level size reduction.
  • Comments carrying licensing notices, like the /*! preserve */ style some libraries use, may get stripped here - check license requirements before distributing minified third-party code.
  • Template literals and regular expressions can contain characters that look like code but aren't, such as // inside a regex, so always test the output rather than assuming minification is risk-free.
  • For real production use, pair this with proper bundling and tree-shaking, since removing unused imports usually saves far more size than whitespace removal alone.

MORE QUESTIONS

Does this minifier rename variables like production tools such as Terser do?
No, it focuses on removing comments and whitespace while keeping identifiers as-is, which keeps the output more debuggable but means the size reduction is smaller than a full mangling minifier achieves.
Can minifying JavaScript change how the code behaves?
It shouldn't, since only formatting is altered, but code that relies on exact whitespace, which is extremely rare and mostly tied to automatic semicolon insertion edge cases, could theoretically behave differently, so always test minified output before deploying.
Will this remove console.log statements or debugger keywords?
No, it only strips comments and whitespace. Removing debug statements requires a separate dead-code-elimination step or deleting them manually before minifying.
Is minified JavaScript the same as obfuscated JavaScript?
No, minification is about size reduction and stays fairly easy to re-indent and read again, while obfuscation deliberately makes code hard to understand through renaming and control-flow tricks, which is a different goal entirely.

RELATED GUIDES

What is Minification?
How minification reduces HTML, CSS, and JavaScript file sizes, what gets removed, how it differs from compression, and which tools to use.
Read →
JavaScript Minifier — UtilYard