JavaScript Minifier
Free online JavaScript minifier and JS compressor that shrinks your code by up to 60%. Removes comments, whitespace and unnecessary characters without changing how your code runs. Choose whether to keep license comments, then copy or download the minified file ready to ship. Runs entirely in your browser — no signup, no uploads.
Paste Your JavaScript
Readable JS in, tiny JS outCtrl+Enter (or Cmd+Enter) inside the textarea to minify instantly. This minifier only removes comments and whitespace — it does not rename variables or transform logic.
Output
Ready when you areYour minified JavaScript will appear here
Paste some JS and click Minify JavaScript to shrink it.
What does this JavaScript Minifier do?
This free online JavaScript minifier (also called a JS compressor) removes every byte that a browser does not need: whitespace, line breaks, indentation and regular comments. The result is a much smaller script that behaves exactly the same when run but downloads faster and improves your PageSpeed score.
Minification is one of the easiest performance wins for any website. A typical hand-written JavaScript file loses 30–50% of its size the moment you minify it, and files that carry a lot of comments and indentation can shrink by 60% or more. For high-traffic sites, that translates into real savings on bandwidth and real improvements in Core Web Vitals.
The tool has a couple of sensible options so you can control exactly what happens. You can preserve important comments (the ones starting with /*!) — this is the convention for license headers and legal notices. You can also let the minifier add semicolons after closing braces where ASI (Automatic Semicolon Insertion) might otherwise kick in — safe by default and helps avoid subtle bugs when you concatenate multiple minified files.
Everything runs locally in your browser. The code you paste never leaves your device, there is no signup, and there are no usage limits. Minify as much JavaScript as you want, as many times as you want, for personal or commercial projects.
How to minify JavaScript code
- Paste your JavaScript into the input box on the left. Any readable script works — hand-written, exported from a bundler, or the output of a TypeScript build.
- Choose your options. Keep important comments on if your file has license headers. Leave the semicolon safety on unless you know your code is safe without it.
- Click Minify JavaScript. The tool rewrites your script in a compact form and shows the result on the right.
- Check the savings. The stats panel shows your input size, output size, bytes saved, reduction percentage, and the number of lines in the output.
- Copy or download. Use Copy Output to grab the minified JS, or Download .min.js to save it with the conventional filename suffix.
Why use this JavaScript Minifier?
Instant compression
Minification happens in your browser the moment you click. No server round-trip, no waiting, no upload limits.
Safe by default
Preserves license comments, keeps needed spaces between tokens, and adds semicolons where ASI edge cases might break concatenated files.
Live stats
See input size, output size, bytes saved, reduction percentage and total lines — all updated the moment you minify.
Modern ES syntax
Understands template literals, arrow functions, optional chaining, nullish coalescing, async/await, classes and private fields.
100% private
Everything runs locally. The code you paste never leaves your device — no server, no logs, no tracking.
Works offline
Once the page loads, you can minify JavaScript without an internet connection. Bookmark it for offline work.
What exactly gets removed?
Here is a complete list of what the minifier strips out and what it preserves, so you know exactly what to expect.
| Element | Default behaviour | Notes |
|---|---|---|
| Whitespace & line breaks | Removed | Spaces, tabs, newlines between tokens |
| Indentation | Removed | Entire leading whitespace is dropped |
Regular comments (// and /* */) | Removed | No effect on runtime |
Important comments (/*! ... */) | Preserved (toggleable) | Convention for license and legal headers |
| Spaces between operators | Removed | a + b becomes a+b |
| Spaces around keywords | Removed when safe | if (x) becomes if(x), but typeof x keeps its space |
| String literals | Preserved exactly | Contents inside '...', "..." and backticks are never touched |
| Template literals | Preserved exactly | ${...} expressions inside are treated as part of the string |
| Regex literals | Detected and preserved | Handled with the keyword/punctuation heuristic |
| Identifiers & variables | Untouched | No renaming, no scope analysis |
| Function names | Untouched | Names remain the same |
| Syntax & behaviour | Identical | Only whitespace and comments are changed |
If you need the smallest possible file, look at dedicated tools like Terser or esbuild — they perform variable renaming, dead-code elimination and constant folding on top of the whitespace-level minification this tool does.
Who uses a JavaScript minifier?
Anyone who ships a website or web app cares about JavaScript size. Here are the most common use cases:
Front-end and full-stack developers
- Minify JS before deploying to production, as a one-off or as part of the build pipeline
- Quickly shrink an inline script embedded in a single HTML file
- Compare input and output byte counts to report compression savings to the team
- Strip leftover debug comments from a script that was shared by a contractor
SEO and performance engineers
- Reduce JS file size to improve First Input Delay (FID) and overall PageSpeed score
- Trim render-blocking JavaScript on the critical path so above-the-fold content paints sooner
- Audit large third-party scripts before deciding whether to keep them
No-code and CMS users
- Minify custom JS injected through a website builder or theme settings
- Clean up exported snippets from a design tool before pasting them into a live site
Students and learners
- See how much whitespace and comments contribute to file size
- Understand the practical difference between beautified and minified JavaScript
JavaScript minify vs. JavaScript beautify — what is the difference?
These two operations are opposites, and each has its own job.
| Mode | What it does | Best for | Typical size change |
|---|---|---|---|
| Minify (this page) | Removes whitespace and comments. Collapses code into the smallest safe form. | Production deployment, performance optimisation, bandwidth savings | 30–60% smaller |
| Beautify / Format | Adds indentation, line breaks and spacing. Expands compact code into a readable structure. | Development, debugging, code review, learning | Larger (adds whitespace back) |
For a two-way workflow, use our JavaScript Formatter to beautify your scripts, then this JavaScript Minifier to ship them to production. Both tools use the same tokenizer, so a round-trip through them preserves the original script exactly.
JavaScript minification best practices
Here are a few things to keep in mind so your minified JS stays healthy in production:
- Always keep the source file. Minified JS is very hard to edit by hand. Keep your original readable file in version control and minify as a build step.
- Enable gzip or brotli on your server. Minification and gzip work best together — the minifier strips the content, the server compresses the remaining bytes.
- Preserve license comments. If your script includes a license header, keep
/*! ... */comments so the license survives minification. - Use cache-busting filenames. Name your minified file
script.min.jsand add a content hash when serving so browsers do not serve stale code. - Do not edit the minified file directly. If you need to change something, edit the source and re-minify. Otherwise you will quickly end up with two divergent versions.
- Test minified code before shipping. Especially if you rely on line breaks for ASI (automatic semicolon insertion). The semicolon safety option helps but is not a silver bullet.
- Use a source map for debugging. Dedicated tools like Terser can emit a source map that points back to your original code, so browser dev tools still show readable lines.