Skip to content
ToolZone

JS Minifier

Compress JavaScript code by removing whitespace and comments and shortening variable names where safe, reducing file size for faster page loads.

Runs in your browser. Nothing you enter or upload leaves your device.

Input
Minified output…

Removes comments and whitespace without renaming variables. Strings are kept; regex literals containing quotes may break, so use a build tool for production.

Keyboard shortcuts

Run the main action
⌘ / Ctrl + Enter
Copy the result
⌘ / Ctrl + Shift + Enter
Download the result
⌘ / Ctrl + S
Paste a file or image into file tools
⌘ / Ctrl + V
Search all tools
⌘ / Ctrl + K
Show these shortcuts
?

You can also drop files anywhere on the page.

About the JS Minifier

The JS Minifier shrinks JavaScript by deleting comments, collapsing whitespace and removing spaces around punctuation, while keeping strings and template literals exactly as written. It keeps the line breaks JavaScript needs for automatic semicolon insertion, so code without semicolons still works.

How it works

The tool scans the code once, setting aside strings and template literals so nothing inside quotes changes, and dropping /* */ and // comments. It then collapses whitespace, removes spaces next to punctuation such as { } ( ) ; , : = < > * / & | ! and ?, and keeps a line break wherever JavaScript's automatic semicolon insertion might need one.

This is a lightweight scan, not a full parser. It understands strings, template literals and comments, but not regular expression literals, and it does not rename variables or remove dead code the way production tools such as Terser or esbuild do. Test the output, especially if your code contains regex literals with quotes or slashes.

How to use

  1. 1

    Paste your JavaScript into the input box, or click Open file.

  2. 2

    Review the minified output and the size cards.

  3. 3

    Copy or download the result, then test it before using it.

Worked examples

A small function with comments

You want a compact version of a helper function to paste inline.

Input
/* Adds two numbers */ function add(a, b) { // return the sum return a + b; }
Result
function add(a,b){return a+b;}

Both comments are removed, the line breaks collapse, and spaces around the comma, braces and + are dropped. The input is 81 characters and the output is 30, so the tool reports 51 saved (63%).

Limitations
Regular expression literals aren't recognised, so a quote or // inside one (such as /'/) can break the output. It does not rename variables or remove dead code; use a build tool such as terser or esbuild for production bundles. Spaces around + and - are kept so expressions like a - -b keep their meaning.
Assumptions
Input is plain JavaScript with semicolons at the end of statements. Sizes are measured in UTF-8 bytes, and the Gzipped card shows the size after compression.
Privacy
Minification runs in your browser and the code you paste is not sent to a server or saved.

Frequently asked questions

Is minified JavaScript still readable?+

Not easily. With comments and most line breaks gone, the code is packed onto very few lines. Keep your original source file for development and only use the minified copy where size matters.

Can minifying JavaScript break my code?+

With this tool, yes, in some cases. It works with text patterns rather than a JavaScript parser, so URLs in strings, code without semicolons, and expressions like a - -b can be altered. Always test the output.

Does it shorten variable names?+

No. It only removes comments and whitespace. Renaming variables (mangling) requires a full parser, which build tools like Terser and esbuild provide.

How much smaller will my file get?+

It depends on how much of the file is comments and indentation. Heavily commented, well-indented code often shrinks by 30 to 60 percent; already compact code shrinks much less. The tool shows the exact saving for your input.

Is my code uploaded anywhere?+

No. The minification is done by JavaScript running in your browser tab.

Related tools