JavaScript Minifier
Remove comments and extra whitespace from JavaScript in your browser. It does not rename your variables, so the result is smaller but not as small as Terser produces. In exchange it is simple, predictable and private.
JavaScript input
Minified JavaScript
Your minified JavaScript will appear here. Paste code on the left or press Load sample.
Options
How to minify JavaScript
- Add your code. Paste it, drop a .js file onto the page, or press Load sample.
- Read the saving. The minified code appears as you type, with the size before and after. A syntax problem it cannot read is reported with a line and column.
- Copy or download. Copy the result or save it as a .min.js file.
Untick the license option if you want every comment removed.
Before
// add two numbers
function add(a, b) {
return a + b; /* sum */
}After
function add(a,b){return a+b;}What this minifier does and does not do
It removes comments, indentation and blank lines, and collapses the spaces around operators and punctuation where that is safe. It does not rename local variables, shorten property names, remove dead code or rewrite expressions. Tools such as Terser and esbuild do those things, and they usually produce a file that is noticeably smaller than this one.
Because nothing is renamed or reordered, the code that comes out behaves the same as the code that went in, which makes this a good fit for small scripts, snippets, bookmarklets, inline code and quick checks where setting up a build step would be overkill. For a production bundle, use a build tool.
| Feature | This tool | Terser or esbuild |
|---|---|---|
| Remove comments and whitespace | Yes | Yes |
| Keep license comments | Yes, by default | Yes, with an option |
| Rename local variables | No | Yes (mangling) |
| Remove unused code | No | Yes |
| Source maps | No | Yes |
| JSX or TypeScript | No, plain JavaScript only | esbuild yes, Terser after compiling |
| Needs an install or a build step | No | Yes |
How it stays safe
Minifying JavaScript by deleting whitespace sounds simple, but a few cases break code if handled carelessly, and the tool reads the code token by token so it can get them right.
| Case | What the tool does |
|---|---|
| Line breaks and automatic semicolon insertion | A line break is kept wherever removing it would change how the code is read, for example after return or before a line that starts with a bracket. |
| Regular expressions and division | It tells a / b from a regular expression by the token before it, and never changes the text of a regex. |
| Template literals | Text inside backticks is kept as written, including nested ${ } expressions. |
| Strings | Contents, including escapes, are copied unchanged. |
a + +b and a - -b | A space is kept so two operators do not merge into ++ or --. |
| License comments | Comments that start with /*! or contain @license are kept unless you turn the option off. |
In our testing, about 700 real and generated JavaScript files were minified and then parsed again, and the syntax tree was identical to the original every time. Savings averaged about 27 percent. Treat that as a guide, since heavily commented code saves more and already compact code saves less.
Good to know
- Private by design
- The code is minified in your browser with JavaScript. It is not uploaded, so proprietary source stays on your device.
- Plain JavaScript only
- JSX, TypeScript and other syntax that needs compiling is not supported. Compile it first. Modern syntax such as arrow functions, classes, async functions and template literals is supported.
- Clear errors
- If something cannot be read, such as an unclosed string or template, you get a line and column and a button that jumps to it.
- Not a syntax checker
- It stops at problems that stop it from reading the code. It does not catch every mistake that a full parser would, so run your tests on the output.
- Related tools
- Working with data? Try the JSON Minifier or the JSON Formatter.
Frequently asked questions
How do I minify JavaScript online?
Paste your code or drop a .js file on the page. The minified result appears straight away with the size before and after. Press Copy, or Download .min.js to save it.
Is my code uploaded to a server?
No. The code is minified in your browser tab and nothing is sent anywhere, so private source code stays on your device.
Does it rename variables like Terser?
No. It only removes comments and unnecessary whitespace. Renaming local variables, which Terser calls mangling, gives smaller files but needs a full understanding of scope, and this tool deliberately does not do it. For production bundles use Terser or esbuild.
Will minifying break my code?
It is designed not to. It keeps the line breaks that automatic semicolon insertion depends on, tells regular expressions from division, and copies strings and template literals unchanged. We checked about 700 files by parsing the input and the output and comparing their syntax trees; all matched. Still, run your tests on minified code before you ship it.
How much smaller will my file be?
On our test files the average saving was about 27 percent. Code with many comments and generous indentation shrinks the most. Code that is already compact shrinks little.
What happens to comments?
They are removed, except license comments that start with /*! or contain @license, which are kept by default because many licenses require the notice to stay with the code. Untick the option to remove those too.
Does it support modern JavaScript, JSX or TypeScript?
Modern JavaScript such as arrow functions, classes, async and await, optional chaining and template literals is supported. JSX and TypeScript are not, because they have to be compiled to plain JavaScript first.
Does it create a source map?
No. If you need to debug minified code in the browser, use a build tool such as esbuild or Terser, which can write a source map.
Why does it report an error?
The tool reads the code token by token. An unclosed string, template literal, comment or regular expression stops it, and the message gives a line and column. Fix that spot and the output updates.
Is minified JavaScript the same as obfuscated?
No. Minifying makes code shorter. Obfuscating makes it hard to read on purpose. This tool does only the first, and because it keeps your names, the output is still fairly readable if you format it again.