The JavaScript Minifier reduces the size of your code by removing comments and collapsing the extra whitespace, while carefully leaving the contents of strings, template literals and regular expressions untouched. The result is a leaner script that keeps the same behaviour but drops the indentation, blank lines and notes that inflate a source file.
It is aimed at developers who want a quick, dependency-free way to shrink a small script, a snippet or a utility file before embedding or shipping it. When you do not need a full build pipeline, pasting code here gives you an immediate compact version without installing anything or configuring a bundler.
Everything runs locally in your browser using JavaScript, so the code you paste is never uploaded, logged or stored. That keeps proprietary logic and unreleased scripts entirely on your own device while you minify them.
Features
- Removes both single-line and multi-line comments throughout the code.
- Collapses runs of whitespace so indentation and blank lines no longer inflate the file.
- Protects the contents of single-quoted, double-quoted and template string literals.
- Detects regular expression literals and copies them verbatim so their spacing is preserved.
- Keeps a newline where the source had one so automatic semicolon insertion is respected.
- Reports the original and minified character counts plus the percentage of size you saved.
- Copies the minified script or downloads it as a file ready to embed or ship.
How to use JavaScript Minifier
- Paste your JavaScript code into the input box.
- The tool instantly strips comments and collapses the whitespace outside of strings and regex.
- Check the statistics to see how many characters and what percentage you saved.
- Review the output to confirm it still reads and behaves the way you expect.
- Copy the minified script or download it as a file to embed in a page or ship with your project.
Benefits
- Smaller scripts download faster, improving page load and perceived performance.
- Stripping comments removes internal notes before code ships to a public page.
- A quick, dependency-free minify avoids setting up a full build tool for a small file.
- Compact JavaScript is easy to inline in a page or embed as a string.
- The size statistics quantify exactly how much smaller the script became.
- Because minification is local, proprietary logic never leaves your own device.
Honest limitation up front: this is a safe, lightweight minifier, not a full compiler like Terser. It removes comments and whitespace and protects strings and regular expressions, but it does not rename variables, remove dead code or perform the aggressive transformations that a true optimiser applies. For production builds of large applications you should still use a dedicated bundler and minifier; this tool is best for quick jobs on small scripts and snippets.
Because collapsing all newlines could change the meaning of code that relies on automatic semicolon insertion, the minifier deliberately preserves a newline wherever the source had one, while stripping the surrounding indentation and blank lines. This conservative choice trades a little extra size for safety, keeping constructs like a bare return followed by a value on the next line behaving exactly as written.
The minifier walks through your code character by character, tracking when it is inside a string, a template literal, a comment or a regular expression, so it never mistakes code punctuation inside a string for something to collapse. Regular expression detection relies on common preceding-token heuristics rather than a full parser, so in rare ambiguous cases such as a regex following certain keywords it may not be detected; review the output before shipping anything critical.