This JavaScript minifier makes code smaller by removing comments and whitespace the engine does not need. It is intentionally conservative: variable names are not shortened, and code is not rewritten, reordered or evaluated. Paste your JS, and you get the compact version with the size before and after.
How to use the JavaScript Minifier
- Paste your JavaScriptPaste a script or a snippet. Modern syntax, including template literals and regular expressions, is recognised.
- Choose the optionsKeep "Join lines where it is safe" on for the smallest result, or turn it off to keep one statement per line.
- Copy or downloadCheck the saving, then copy the output or download script.min.js. Test the minified file before you publish it.
What this JavaScript minifier does and does not do
Build tools such as Terser or esbuild parse a program fully and then rewrite it: they rename local variables, remove unused code and restructure expressions. That gives the smallest files, and it is what you should use in a real build pipeline.
This JavaScript minifier does a simpler, safer job that needs no setup. It reads the code token by token and:
- removes
//line comments and/* */block comments (licence comments starting with/*!or containing@licenseor@preservecan be kept); - removes indentation and spaces that are not needed to separate two words or operators;
- keeps string literals, template literals and regular expressions exactly as written.
It does not rename anything, drop semicolons, remove dead code or check for syntax errors. Your code is never executed.
Line breaks and automatic semicolons
JavaScript inserts semicolons automatically at some line breaks, so a line break can be meaningful. Deleting every newline would turn
let a = b
(c || d).run()from two statements into one function call. To stay safe, the minifier keeps a line break unless joining is certain to be harmless: after ;, {, ,, ( or [, or before }, ) or ]. Code written with semicolons therefore collapses to a few long lines, while code written without them keeps one statement per line.
One honest limitation: telling a regular expression from a division sign without a full parser relies on the token before the slash. The rule used here is right for normal code, but an unusual construct, such as a regex literal directly after a closing parenthesis, may be read as division. The result is still valid in nearly all cases, but always run your tests on the minified file.
Typical savings are 20 to 40 percent on commented, indented source. Nothing is uploaded. For styles and markup, see the CSS minifier and the HTML minifier.
Frequently asked questions
What does this JavaScript minifier remove?
Only comments and whitespace that the JavaScript engine does not need. Names, strings, regular expressions and the order of the code stay exactly the same.
Does it shorten variable names?
No. Renaming needs a full parser and scope analysis. This is a conservative minifier; for name mangling and dead-code removal use a build tool such as Terser or esbuild.
Can minifying break my code?
It is designed not to: line breaks are kept wherever automatic semicolon insertion could depend on them. Still, test the minified file, especially if the code uses unusual regular expression placement.
Why are some line breaks still there?
They are kept on purpose where removing them might join two statements. If your code ends statements with semicolons, almost all line breaks disappear.
Is my code uploaded or run?
No. The script is processed as text inside your browser. It is never executed and never sent to a server.
Last updated 24 November 2026 by the TheTechFolk team.