JavaScript Minifier
Runs entirely in your browser
Safely shrink JavaScript by removing comments and indentation. This only rewrites text — it never executes your code.
What is JavaScript Minifier?
JavaScript Minifier removes comments and indentation to shrink your code, while keeping original line breaks so behavior can never silently change due to automatic semicolon insertion. It's a safe, conservative minifier rather than a full AST-based one.
How to use JavaScript Minifier
- Paste your JavaScript into the Input box.
- Click Minify.
- Copy the compressed result from the Output box.
Features
- Strips // and /* */ comments.
- Removes indentation and unnecessary spacing.
- Preserves original line breaks to avoid ASI-related behavior changes.
- Correctly recognizes strings, template literals and regex literals.
- Never uses eval — your code is never executed.
- 100% client-side — your code never leaves your browser.
Example
This commented function (139 characters):
// Greets a user by name
function greet(name) {
if (name) {
return `Hello, ${name}!`;
}
// fallback greeting
return "Hello!";
}
becomes this (81 characters — a 42% reduction):
function greet(name) {
if (name) {
return `Hello, ${name}!`;
}
return "Hello!";
}
Tips for using JavaScript Minifier
- This tool reuses the identical tokenizer as JavaScript Formatter — the same string, template-literal and regex detection — so stripping comments and whitespace here carries the same guarantee against corrupting those tokens.
- A removed
//line comment still forces a line break afterward. In the Example above, deleting// fallback greetingdidn't merge}andreturn "Hello!";onto the same line, because code can't legally follow//on that original line. - A
/* block */comment, by contrast, is simply deleted without forcing a line break, since a block comment can end mid-line without affecting what comes next. - The percentage saved depends entirely on how much of your original file was comments and indentation — the 42% shown in the Example reflects that specific heavily-commented snippet, not a general guarantee for all code.
Is JavaScript Minifier safe?
Yes. By keeping original line breaks and only stripping comments and indentation — avoiding the automatic-semicolon-insertion risk explained in the FAQ below — this tool never needs to execute your code to minify it safely, and everything happens locally in your browser without any upload to our servers.
Frequently Asked Questions
Does this execute my code?
No. This tool never uses eval or runs your code — it only rewrites the text.
Why does the output keep line breaks instead of becoming one line?
Removing a line break can silently change what JavaScript does, because of automatic semicolon insertion (ASI) — doing this safely requires a full parser, not just a tokenizer. This tool keeps original line breaks and instead strips comments and indentation, which is where most of the size savings come from anyway.
For maximum compression, what should I use instead?
A build-time tool like Terser or esbuild, which parses a full AST and can safely rewrite statement boundaries, rename variables and remove line breaks.