Runs in your browser. Your files and text never leave your device - nothing is uploaded.
Minify JavaScript Online, Free
The Tools Kit’s free Minify JS tool compresses JavaScript by stripping comments, collapsing whitespace and removing the spaces around operators and punctuation. Paste your code and the minified version appears instantly, with the character count and the percentage saved, so you can see how much a script shrinks before you ship or share it.
It is a lightweight, text-based JS minifier that runs entirely in your browser: nothing is uploaded. That makes it quick for inline scripts, snippets and size estimates, but it does not parse JavaScript, so it keeps every variable name and can mishandle strings that contain //. For production bundles, use a parser-based tool such as Terser or esbuild. Working on stylesheets too? The CSS minifier does the same job for CSS.
How to Minify JS
- 1
Paste your JavaScript
Paste or type your code into the JavaScript Input box. A sample function is loaded so you can see how the tool works; replace it with your own code. The character count updates as you type.
- 2
Read the minified output
The Minified JS panel updates instantly, with no button to press. Comments are removed and whitespace is collapsed or dropped around operators and punctuation.
- 3
Check the size saving
The label above the output shows the new character count and how many percent smaller it is than the input, so you get a quick before-and-after comparison.
- 4
Test, then copy
Scan the output for strings that contain URLs or deliberate spacing, then click Copy Minified and run the code once before you rely on it.
There is no account, file size setting or usage limit.
What This JavaScript Minifier Does, Step by Step
Under the hood the tool applies five text replacements in a fixed order. Knowing them makes it easy to predict the output and to spot the cases where it goes wrong.
- Delete everything from
//to the end of the line (line comments). - Delete everything between
/*and*/(block comments). - Collapse blank lines.
- Turn every run of spaces, tabs and line breaks into a single space.
- Remove the spaces on either side of
= + - * / % & | ^ < > ! ? : , ; { } ( ) [ ], then trim the start and end.
Because these rules match text rather than JavaScript syntax, they also apply inside strings, template literals and regular-expression literals. The cases to watch for:
- URLs in strings.
"https://example.com"is cut at the//, leaving"https:and losing the rest of the line. - Code without semicolons.
const a = 1on one line andconst b = 2on the next becomeconst a=1 const b=2, a syntax error. Add semicolons before minifying. - Spacing inside strings.
"a + b"becomes"a+b", and line breaks inside template literals become spaces. - Unary operators.
a - -bbecomesa--b, which JavaScript reads as a decrement.
If your code builds patterns with regular expressions, check them in the regex tester and compare them after minifying. A literal that ends in an escaped slash, such as /^\//, contains the same // the comment rule looks for, so const isAbs = /^\//.test(p); is cut down to const isAbs=/^\.
Example: Minified JavaScript Before and After
Here is a short function with a comment and four-space indentation, 185 characters in total.
// Sum a list of prices
function totalPrice(itemList) {
let runningTotal = 0;
for (const item of itemList) {
runningTotal += item.price;
}
return runningTotal;
}This tool removes the comment and the whitespace, giving 124 characters, about 33% smaller. Every name is unchanged:
function totalPrice(itemList){let runningTotal=0;for(const item of itemList){runningTotal+=item.price;}return runningTotal;}A parser-based minifier such as Terser goes further. It renames the local names itemList, runningTotal and item, drops the braces around the single-statement loop body and the final semicolon, and reaches 68 characters:
function totalPrice(t){let o=0;for(const r of t)o+=r.price;return o}Even a renaming minifier leaves totalPrice alone, because code elsewhere may call a top-level function by name, and leaves .price alone, because object properties can be read by name at runtime. Only names that cannot be seen outside the function are safe to shorten.
Minify, gzip and Brotli are not the same thing
These three are often treated as alternatives. They are not - they stack, and using all three gives a smaller result than any one alone.
| Minification | gzip | Brotli | |
|---|---|---|---|
| What it changes | Rewrites the source to be shorter | Compresses the bytes in transit | Compresses the bytes in transit |
| When it happens | Build time, once | Every response, by the server | Every response, by the server |
| What the browser receives | Shorter source | Compressed bytes, decompressed on arrival | Compressed bytes, decompressed on arrival |
| Helps parse time | Yes - there is genuinely less to parse | No - the file is identical once decompressed | No - the file is identical once decompressed |
| Typical extra saving | 20–40% on unminified JavaScript | 70–80% on text | Roughly 15–20% better than gzip |
The order matters: minify first, then let the server compress. Minification is the only one of the three that reduces work for the browser’s parser, because gzip and Brotli hand over exactly the same javascript they were given once decompression finishes. Compression is usually already switched on at the CDN, which is why minifying is the step most likely to be missing.
Common uses
- Estimating how much a script will shrink before setting up a build tool
- Compacting a small inline
<script>for a static HTML page or email template - Turning a short script into a one-line bookmarklet
- Removing comments from a code sample before sharing it
- Checking how much of a file is comments and indentation
A bookmarklet must be a single line, so minifying is the first step; the second is percent-encoding characters such as spaces and quotes with the URL encoder before you put it after javascript:. If you want to show a script as text on a web page instead of running it, escape its <, > and & with the HTML entity encoder. Data that only looks like JavaScript, such as a JSON config, is better compacted or pretty-printed in the JSON formatter, which parses it properly.
JavaScript minification terms
| Term | What it means |
|---|---|
| Minification | Rewriting source code to be shorter without changing what it does, mainly by removing comments and whitespace |
| Mangling | Renaming local variables and parameters to short names such as t or o; parser-based minifiers do this, this tool does not |
| Dead-code elimination | Removing code that can never run, such as an if (false) branch; requires a real parser |
| ASI | Automatic semicolon insertion: JavaScript fills in missing semicolons at line breaks, which is why removing line breaks can break code written without semicolons |
| Source map | A .map file that links minified code back to the original lines for debugging; build tools generate them, this tool does not |
| Unminify / beautify | The reverse operation: re-adding indentation and line breaks to make compact code readable again |
Frequently Asked Questions
Paste your code into the JavaScript Input box. The minified version appears instantly in the Minified JS panel, with its character count and the percentage saved shown above it. Click Copy Minified to copy the result. There is no sign-up, upload or button to press.
It removes // line comments and /* block */ comments, collapses blank lines and runs of whitespace into a single space, and drops the spaces around operators and punctuation such as = + - * / , ; : ( ) { } and [ ]. Everything else is left as written.
No. Variable, function and property names are kept exactly as you wrote them. The tool also does not remove unused code, drop braces or rewrite expressions. Those optimizations need a parser-based minifier such as Terser or esbuild.
It depends on how much of the file is comments and indentation. The sample code that loads with the tool goes from 151 to 112 characters, 26% smaller, and the worked example on this page goes from 185 to 124 characters, 33% smaller. Code that is already compact will shrink much less.
Yes, in some cases. The tool uses text replacements rather than a JavaScript parser, so it cannot tell code from the contents of strings. Code that leaves out semicolons and relies on line breaks will break, and extra spaces inside strings and template literals are collapsed. Always test the output.
The comment remover deletes everything from // to the end of the line, even inside a quoted string, so "https://example.com" becomes "https: and the rest of that line is lost. Move URLs into a separate file or config, or use a parser-based minifier for code that contains them.
No. Minification runs entirely in your browser with JavaScript on the page. Your code is not sent, stored or logged anywhere.
Characters. The counts are the length of the text, which equals the byte size for plain ASCII code but is lower than the UTF-8 byte size if your code contains accented letters, emoji or other non-ASCII characters.
For a small inline script or a snippet you have tested, it can be fine. For application code, use a build tool such as Terser or esbuild, which parse JavaScript, rename local variables safely and can produce source maps for debugging.
No. Minification rewrites the source once to make it shorter, while gzip and Brotli compress the bytes each time the server sends the file. They stack: minify first, then let the server compress the result.
Minified code cannot be turned back into the original comments or variable names, but its layout can be restored. Paste it into the code beautifier to add indentation and line breaks back so it is readable again.
Related developer tools
See every formatter, encoder and converter in the developer tools collection on The Tools Kit.
Reviewed by Raja Jahangir · Last reviewed: October 7, 2026
What does minifying JavaScript do?
Minifying JavaScript removes comments and unneeded whitespace, and full minifiers such as Terser also shorten local variable names, without changing how the code behaves. Smaller scripts download and parse faster. The minifier on this page removes comments and whitespace only and keeps every name as written, so the saving depends on how much of the file is comments and indentation.
