JS Minifier
Strip JS comments and whitespace conservatively.
Use the JS Minifier tool
What this js minifier does
JS Minifier removes comments and collapses unnecessary whitespace. It tracks strings, template literals and regular expressions so their contents are not altered, which avoids the most common source of minifier breakage.
It is deliberately conservative: identifiers are not shortened, dead code is not removed and syntax is not transpiled. Use esbuild, terser or your framework build for production bundles, and re-run tests against minified output.
Why use it
- Remove comments before embedding a small script in a page.
- See a rough size saving for a self-contained function.
- Produce a compact copy without leaving the browser.
How to use it
- 1Paste the JavaScript.
- 2Compare the before and after sizes.
- 3Copy or download the output.
- 4Run the script and your tests; do not assume semantic equivalence.
Worked examples
Function with comments
Input
// Toggle the panel
function toggle(panel) { return panel.hidden = !panel.hidden; }Output
function toggle(panel){return panel.hidden=!panel.hidden}Regular expression
Input
const r = /\/\* not a comment \*\//g;
Output
The regular expression pattern is preserved.
Common mistakes
- Assuming comment removal cannot change behaviour; a comment containing sourceMappingURL or conditional-compilation directives may matter.
- Minifying code that relies on automatic semicolon insertion in ambiguous places.
- Skipping tests because the file merely got smaller.
Frequently asked questions
Does it shorten variable names?
No. It only removes comments and whitespace. Identifier mangling needs a full parser and is out of scope.
Is the output guaranteed to work?
No. Minification is a transformation; always run the code after minifying.
Can it handle TypeScript or JSX?
Not reliably. Transpile to plain JavaScript first.
Does it preserve license comments?
Regular comments are removed. Keep license text in a separate notice if your dependencies require it.