JS Minifier
Minify JavaScript by removing comments and unnecessary whitespace.
Recommended tools
Free CDN, DNS, and edge hosting for developers.
Affordable domains and SSL certificates.
Affiliate links — we may earn a commission if you sign up.
About the JS Minifier
The JS Minifier shrinks JavaScript without changing what it means, using a tokenizer that understands the language well enough to tell division from a regex literal — const ratio = 4 / 2 keeps its division, while const pattern = /[a-z]+/gi survives intact. String, template, and regex literals are preserved byte for byte, including template interpolations, so no data is ever altered. Three switches drive the compression: Strip comments removes // and /* */ comments, Collapse whitespace joins tokens where it is safe, and Drop ; before } removes the last semicolon of a block. Crucially, newlines after return, throw, yield, break, and continue are preserved so automatic semicolon insertion can never silently change control flow. An honest banner sets expectations: this is a basic minifier with no variable renaming or dead-code elimination — for production you should still run terser or esbuild — but for quick compression and size checks it is immediate. Stats show original/minified bytes and savings, and the output downloads as script.min.js.
Examples
const ratio = 4 / 2; const pattern = /[a-z]+/gi; const lines = text.split(/ /);
const ratio=4/2;const pattern=/[a-z]+/gi;const lines=text.split(/ /);
function add(a, b) {
return a + b; // sum
}
const total = add(2, 3);function add(a,b){return a+b}const total=add(2,3);const greeting = "Hello, world!"; const pattern = /\d+/g;
const greeting="Hello, world!";const pattern=/\d+/g;
How to use
- 1
Paste your JavaScript into the JavaScript input textarea, or click Load sample.
- 2
Set the switches: Strip comments, Collapse whitespace, Drop ; before }.
- 3
Read the informational banner — this is a basic minifier, not a full optimizer.
- 4
Check the Original, Minified, Saved, and Savings stats for the size change.
- 5
Download the result as script.min.js.
Common use cases
- Quickly shrinking a small script for a bookmarklet or user script.
- Estimating payload savings before wiring up a production minifier.
- Comparing your hand-minified output against a reference implementation.
- Preparing compact inline script content for a template or email.
- Checking that a regex-heavy script survives a whitespace-only minifier.
- Learning how tokenizers distinguish regex literals from division.
Best practices
- Do not ship this output to production — there is no renaming or tree shaking; run terser or esbuild afterward.
- Verify the minified result in a browser or with node before relying on it anywhere.
- Keep the readable source in version control and treat the minified file as a build artifact.
- Watch for ASI-sensitive code: the tool preserves newlines after return/throw/yield/break/continue, but avoid relying on tricky ASI patterns.
- Spot-check template literals with interpolation after minifying — they are preserved verbatim by design.
- The stats measure bytes, not performance; minification mainly cuts transfer size, not runtime speed.
Tips
- Load the sample to see comments, a regex, a template, and arrow functions minify together.
- Toggle Collapse whitespace off to isolate what comment stripping alone saves.
- Run the output through node --check in your terminal for a fast syntax sanity check.
- Use the Savings stat to argue for a proper build step in a project that still ships unminified scripts.
Frequently asked questions
Explore more developer tools
Browse the full collection of developer tools on the hub, or jump back to all categories.