JavaScript JS Minifier
Strip comments and collapse whitespace from JavaScript to see how much of a file is formatting rather than code. The minifier runs in your browser on the text you paste, which makes it a quick way to shrink a snippet or inspect the size difference without setting up a build step.
How it works
- 1
Paste the JavaScript you want to compress.
- 2
Run the minifier β comments are removed and whitespace around operators and punctuation is collapsed.
- 3
Compare the before and after size to see what formatting was costing you.
- 4
Copy the result, or keep the original if the code contains the constructs listed under limits below.
What people use it for
- Shrinking a small inline script before embedding it in a page or email template.
- Checking how much of a file is comments and indentation before optimising anything else.
- Compressing a snippet for a character-limited field, such as a tag manager custom template.
- Demonstrating what minification does when explaining a build pipeline.
Supported formats & options
| Input | JavaScript source pasted as text |
|---|---|
| Removed | Line comments, block comments, redundant whitespace and spacing around operators and punctuation |
| Output | Minified JavaScript text, copied to the clipboard |
Key advantages & benefits
Immediate size comparison
You see the original and compressed length together, which answers the practical question of whether minifying this file is worth doing at all.
No build tooling
Useful for a snippet, an inline script or a one-off file where wiring up a bundler would take longer than the task.
Runs locally
The code you paste is processed in the tab, so proprietary source never reaches a server.
Readable output
The result is still valid JavaScript text you can inspect, not an obfuscated blob.
Limits & things to know
- This is a whitespace-and-comment minifier built on pattern matching, not a parser. It does not rename variables, drop dead code or perform the tree-shaking a bundler does.
- Because it does not parse the language, it can corrupt code where comment-like or operator-like sequences appear inside strings, template literals or regular expression literals β a URL such as https://example.com inside a string is the classic case.
- Always verify the output before shipping it. For production builds, use esbuild, Terser or your bundler's minifier, which parse the code properly.
Troubleshooting
The minified code throws an error
Check for strings or regex literals containing // or /* β the pattern matcher treats those as comments. Keep the original file and minify with a parser-based tool such as Terser or esbuild instead.
Automatic semicolon insertion breaks the result
Code that relies on newlines to end statements can change meaning when whitespace collapses. Add explicit semicolons in the source before minifying.
The saving looks small
Whitespace removal alone typically saves far less than gzip or Brotli compression on the server. Enable compression on your host before optimising the source further.
Privacy & data handling
The code you paste is processed by JavaScript in your own browser tab and is never uploaded, which matters when the source is not public.
JavaScript Minifier β Compress JS Code Online Free
This free JavaScript minifier compresses JS files for production by stripping comments, line breaks and superfluous whitespace. Paste a script, minify it, and copy a leaner bundle that parses and executes faster on low-end mobile devices.
- Compress JavaScript for faster load times β smaller scripts mean fewer bytes over the wire and less main-thread parse time β the two costs that dominate JavaScript performance budgets.
- Comment and whitespace stripping β development notes, dead formatting and generous indentation are removed from the shipped output.
- Copy-paste ready β minified JS lands on your clipboard in one click, ready to drop into a build folder, a CMS template or an inline script tag.
- No build tooling required β a practical option when you are editing a WordPress theme, a landing page or a legacy site with no webpack, Vite or Rollup pipeline.
- Private, in-browser minification β unreleased product code and API glue never leave the tab β nothing is uploaded to a minification server.
Minify your stylesheets with the CSS Minifier too, and use the Base64 Converter when you need to inline a small asset into the script itself.
Frequently asked questions
Is minified JS safe to deploy?
Yes, minified code maintains 100% exact functional logic.
Is this safe to use on production code?
Treat it as a quick utility, not a build step. It matches patterns rather than parsing JavaScript, so it can damage code where comment-like or operator-like sequences appear inside strings, template literals or regular expressions. Verify the output, and use esbuild or Terser for anything you ship.
Why did my minified code stop working?
The usual cause is a URL inside a string β the double slash in https:// looks like the start of a comment to a pattern matcher. Code that relies on newlines for automatic semicolon insertion is the other common failure.
Does it rename variables like a real minifier?
No. It removes comments and collapses whitespace only. Variable renaming and dead-code elimination need a parser that understands scope, which is what bundler minifiers do.
Related tools
CSS Minifier & Formatter
Minify CSS code to reduce file size or beautify code
JSON Formatter
Format, validate and minify JSON instantly
Regular Expression (RegEx) Tester
Test and debug Regular Expressions in real-time
URL Slug Generator & Sanitizer
Convert blog titles and text into clean URL slugs