JavaScript Minifier
Compress JavaScript by removing unneeded whitespace and comments, making files smaller for faster websites. No signup. Ideal for optimising JS for web performance.
Share on Social Media:
Paste your JavaScript into this free JS Minifier — or upload a .js file — click Minify, and get smaller code back with the exact bytes saved shown in a table. There are no settings to learn and no signup: the tool strips comments and whitespace, keeps your code working the same, and lets you copy the result or download it as a .js file.
On this page
- How to Minify JavaScript Step by Step
- What Minifying JavaScript Does and Why It Helps
- Minified Versus Regular JavaScript
- Who Uses a JavaScript Minifier
- Pro Tips for Minifying JavaScript
- Common JavaScript Minifying Mistakes to Avoid
- Related Tools You May Need Next
- Frequently Asked Questions
How to Minify JavaScript Step by Step
- Paste your JavaScript. Drop it in the "Enter or Paste Javascript" box. Or click "Upload File" and choose a .js file — the file's contents are loaded into the box for you. The box must not be empty.
- Click "Minify". Nothing happens while you paste; the result only appears after you click the button. Your code is sent to the server, minified there, and the page reloads with the result.
- Read the Result table. It shows three numbers: the original size, the minified size, and how many bytes you saved, with the percentage. Small files show bytes; large files show kilobytes.
- Copy or download the result. Click "Copy to Clipboard" to copy the minified code, or the download button to save it as a file named js-minifier.js — rename it to your own filename before you use it.
- Test it before you ship it. Run the minified code and check it behaves like the original, then use it on your live site while keeping your readable file as the source.

What Minifying JavaScript Does and Why It Helps
JavaScript files are written for people to read: indented lines, blank lines, and comments explaining what the code does. Browsers do not need any of that. Minifying strips it out, so the file that travels to the visitor is smaller and downloads faster — while the code itself does the same thing.
| Feature | What it does | The limit to know |
|---|---|---|
| Paste JavaScript | Type or paste any JS into the input box | The box is required — submitting it empty shows an error |
| Upload File | Reads a .js file into the input box | Only files reported as JavaScript are accepted; if yours is rejected as "Invalid File", paste its contents instead |
| Minify button | Sends your code to the server and returns the minified version | There are no options — no keep-comments setting, no rename-variables setting |
| Result table | Shows Original, Minified and Saved sizes, with the percentage saved | — |
| Copy to Clipboard | Copies the minified code | — |
| Download | Saves the result as js-minifier.js | Rename the file before using it on your site |
What it removes — and what it keeps
The tool only strips formatting. It never rewrites your logic, and it does not shorten variable names or delete code. Everything below was checked with real submissions:
| Part of your code | After minifying |
|---|---|
| // line comments and /* block comments */ | Removed, including multi-line block comments |
| Indentation, blank lines, line breaks inside code | Removed |
| Variable and function names (message, name) | Kept exactly as written — nothing is renamed |
| console.log calls | Kept — the tool does not remove logging |
| Text inside strings, e.g. "https://example.com/path" or "a // b" | Kept exactly — the // inside a string is not mistaken for a comment |
| Regular expressions such as /a\/\/b/g | Kept exactly |
| Template literals such as `Hello ${n}, welcome!` | Kept exactly, including the ${…} part |
| Semicolons inside strings, e.g. "x;y" | Kept exactly |
Your code is sent to the server. This tool is not a browser-only tool: clicking Minify posts your JavaScript to the server, which returns the minified version. Do not paste code you cannot share, such as code containing passwords, API keys, or other secrets.
Worked example: a small function, minified
This function is 175 bytes, comments and blank line included:
| Line | JavaScript |
|---|---|
| 1 | // Greet the visitor |
| 2 | function greet(name) { |
| 3 | // Build the message |
| 4 | var message = "Hello, " + name + "!"; |
| 5 | console.log(message); |
| 6 | return message; |
| 7 | } |
| 8 | |
| 9 | greet("World"); |
After clicking Minify it becomes 105 bytes. The tool's own Result table reads: Original 175 bytes, Minified 105 bytes, Saved 70 bytes (40%).
| Line | JavaScript |
|---|---|
| 1 | function greet(name){var message="Hello, "+name+"!";console.log(message);return message;} |
| 2 | greet("World"); |
Both comments are gone and the blank line is gone, but the names name and message and the console.log are all still there. The output was checked: it is valid JavaScript, and running it prints Hello, World! — the same as the original.
One detail to notice: the tool keeps a line break after the closing brace, before greet("World");. That is normal for this tool and the code still runs exactly the same.
Worked example: a large, comment-heavy file
A test file of 4,000 comment lines and 4,000 short variable lines — 227.22 kB in total — minified to 118.93 kB, saving 108.29 kB (47.66%). Comment-heavy code saves more than code that is already tight, so your own saving depends on how much whitespace and commenting your file carries. Already-minified code, by contrast, saves nothing: pasting a one-line minified function back in returned it unchanged, with 0 bytes saved.
The tool does not check your code. If your JavaScript has a syntax error, the tool minifies it anyway and returns still-broken code, with no error or warning. Always test the minified output before you put it live — a quick run in the browser console or a syntax check catches what the tool will not.
Minified Versus Regular JavaScript
Minified and regular JavaScript hold exactly the same logic. Only the presentation differs — and that difference decides whether a person or a browser gets the better deal.
| Aspect | Minified JavaScript | Regular JavaScript |
|---|---|---|
| Size | Smaller — 175 bytes became 105 bytes in the example above (40% saved) | Larger, with whitespace and comments included |
| Readability | Hard to read — everything squeezed together | Readable, with indentation and comments |
| Comments | All removed | Kept, for the next person who edits the file |
| Variable names | Unchanged by this tool | Unchanged |
| Behaviour | Same, as long as the original code was valid | Same |
| Best for | The live site, for faster loading | Editing and maintaining the source |
This tool only strips formatting. Build-time minifiers that run as part of a deployment pipeline often go further and shorten variable names too, which squeezes out a little more size. If you only need the formatting stripped — for a snippet, a single file, or a quick check of how much your comments weigh — this tool does that job without any setup.

Who Uses a JavaScript Minifier
Web developers shipping production code. A developer minifies JavaScript before deploying, so visitors download a smaller file and the page loads faster.
People speeding up a slow page. Someone fixing page speed minifies their JavaScript as one quick optimisation, alongside compressing images and CSS.
People preparing a site for launch. Before a site goes live, its scripts are minified while the readable originals stay in the project for future edits.
People checking how much comments weigh. A quick paste shows the exact bytes saved, which tells you how much of a file is formatting rather than code.
Anyone with a single file to shrink. No build tool, no install, no account — paste one file, minify it, copy the result.
Pro Tips for Minifying JavaScript
Keep the readable source. Minified code is hard to read and edit. Keep your original file as the source, and minify a copy for live use.
Test the minified output. The tool does not check your code, so run the result once before deploying it. If it prints and behaves like the original, it is safe to ship.
Minify the file you actually ship. Minifying a copy that never reaches your site changes nothing. Replace the live file with the minified version, and keep the readable one in your project.
Expect more saving from comment-heavy code. A file full of comments saved 47.66% in testing, while already-tight code saves little. The Result table tells you the exact number for your file.
If the upload says "Invalid File", paste the contents. The upload checks the file's reported type, not its name. Opening the .js file and pasting its text into the box always works.
Rename the download. The download is always saved as js-minifier.js. Give it your own filename so it does not overwrite a previous download or confuse your project.
Re-minify after every edit. The live file does not update itself. Change the readable source, minify it again, and replace the live file.

Common JavaScript Minifying Mistakes to Avoid
Editing the minified output directly. Minified code is squeezed onto very few lines, so editing it is slow and error-prone. Edit the readable source and minify again.
Losing the readable source. If you keep only the minified file, future changes become very hard. Keep the original alongside it.
Assuming the tool checked your code. It does not validate anything. Broken code in means broken code out, with no warning — test the result.
Expecting it to rename variables or remove console.log. This tool strips formatting only. Names and logging stay exactly as they are.
Expecting it to keep a comment you wanted. Every comment is removed, including licence headers. If a comment must stay in the shipped file, add it back to the minified output yourself — there is no keep-comments option.
Forgetting to re-minify after changes. Editing the readable file does not update the live minified file. Minify again after each edit, or your site serves the old code.
Pasting secrets into the tool. Your code is sent to the server when you click Minify. Never paste code containing passwords, API keys, or private data.
Related Tools You May Need Next
Minifying JavaScript is one part of shrinking a page. Our CSS Minifier does the same for stylesheets, the HTML Minifier does it for HTML, and the JSON Minify tool shrinks JSON to one line — while the JSON Beautifier goes the other way and expands minified JSON into a readable layout. The HTML Viewer lets you view HTML in the browser, and Check GZIP Compression tells you whether a page is served compressed, which is the next size check after minifying.
Frequently Asked Questions
How do I minify JavaScript?
Paste your JavaScript into the input box, or click "Upload File" and choose a .js file, then click "Minify". The Result table shows the original size, the minified size, and the bytes saved. Copy the result or download it as js-minifier.js.
What does minifying JavaScript remove?
It removes comments — both // line comments and /* … */ block comments — plus indentation, blank lines, and line breaks inside the code. It does not remove or change any of your actual logic.
Does minified JavaScript behave the same?
Yes, as long as the original code was valid. Minifying only changes formatting, so the code runs the same. Because the tool does not check your code for errors, test the minified output once before you rely on it live.
Does it rename my variables or remove console.log?
No. Variable and function names stay exactly as written, and console.log calls are kept. This tool only strips comments and whitespace — it does not shorten names or delete code.
Is my code processed in my browser?
No. Clicking Minify sends your JavaScript to the server, which returns the minified version. Do not paste code containing passwords, API keys, or other secrets.
Can I upload a .js file instead of pasting?
Yes. Click "Upload File" and choose a .js file, and its contents are loaded into the input box. If the upload is rejected with "Invalid File", open the file and paste its contents into the box instead.
How do I save the minified code?
Click "Copy to Clipboard" to copy it, or the download button to save it as a file named js-minifier.js. Rename the file to your own filename before using it on your site.
What happens if my JavaScript has an error in it?
The tool minifies it anyway and returns still-broken code, with no error or warning. Fix the error in your original code, minify again, and test the result before deploying it.
How much smaller will my JavaScript get?
It depends on how much whitespace and commenting your file has. A small commented function saved 70 bytes out of 175 (40%), and a comment-heavy 227.22 kB file saved 108.29 kB (47.66%). Already-minified code saves nothing. The Result table gives you the exact number for your file.
Is the JavaScript minifier free?
Yes, it is free and needs no signup or account. Paste your code or upload a .js file, click Minify, and copy or download the result.