JavaScript Minifier
Safely compress JavaScript by stripping comments and extra whitespace while leaving strings, template literals and regular expressions intact — free and instant. Your code stays in your browser and is never uploaded.
How to use the JavaScript Minifier
- Paste your JavaScript. Drop in a script, a module or any block of JS code that you want to make smaller.
- Minify. Press Minify JavaScript. The tool removes comments, indentation and blank lines while keeping your code correct and runnable.
- Copy or download. Copy the compressed code to your clipboard or download it as a
.min.jsfile, and check the size panel to see how much you saved.
About this tool
This free online JavaScript minifier reduces file size by removing line and block comments, stripping indentation, deleting blank lines and collapsing repeated spaces. It is built to be conservative and safe: the code is scanned token by token so that string literals, template literals with ${…} interpolation, and regular expression literals are copied through untouched, and the notoriously ambiguous / character is correctly interpreted as either division or the start of a regex based on context.
Because it never renames variables or rearranges statements, this minifier will not change how your program behaves. It keeps meaningful line breaks so that JavaScript's automatic semicolon insertion still works exactly as it did in your source — a common way that aggressive minifiers silently break code. For maximum compression with dead-code elimination and identifier mangling you would use a full build-time tool, but for quickly shrinking a script safely this runs entirely in your browser, so your code is never uploaded or stored.
Frequently asked questions
Is it safe — will it break my code?
This is a conservative minifier. It only removes comments and redundant whitespace, never renames variables or moves code, and it preserves the line breaks that JavaScript's automatic semicolon insertion depends on. Strings, template literals and regular expressions are detected and left exactly as written, so your program keeps working.
Why does it keep some line breaks instead of putting everything on one line?
Collapsing every newline can silently change behavior in JavaScript because of automatic semicolon insertion — for example after a bare return. To stay safe, this tool keeps one newline where your source had one, which still removes the bulk of the size (comments, indentation and blank lines) without risking correctness.
Does it rename variables or remove unused code?
No. Variable and function names are preserved and no dead-code elimination is performed. That keeps the output easy to relate back to your source and guarantees it behaves identically. For name mangling and tree-shaking, use a build-time bundler such as those found in modern toolchains.
Is my JavaScript uploaded to a server?
No. All parsing and minification happen locally in your browser with client-side JavaScript. Nothing you paste is uploaded, logged or stored, so the tool is safe for proprietary code and works offline once the page has loaded.