How to minify JavaScript
- Paste your JavaScript into the box above.
- Tick Keep license banners if your code carries one.
- Read the minified output that appears right away.
- Check the saving in characters and as a percent.
- Copy the result or download it.
What this JavaScript minifier gives you
- Token based reading so a comment marker inside a string stays safe.
- Correct detection of a regex literal versus a division sign.
- Template literals kept byte for byte with their whitespace.
- Line breaks kept where automatic semicolons depend on them.
- No renaming so stack traces still make sense.
- An option to keep license banners that open source terms require.
Why JavaScript is harder to minify than CSS
CSS has few traps. JavaScript has several. Each one lets a careless minifier produce code that looks fine and then fails when it runs.
The classic trap is the forward slash. In a / b it means division. In /ab+/g it starts a regular expression. The tool must know what came before to tell them apart. A minifier that guesses wrong will delete half a pattern.
Strings cause the same trouble. Take "https://example.com" as an example. The two slashes are not a comment. A simple pattern based minifier treats them as one and cuts the line short. This tool reads tokens first and avoids that.
Automatic semicolon insertion
JavaScript adds semicolons where it thinks you meant one. Its rules depend on line breaks. Remove the line break after a bare return and the function may return something different. The same risk applies after throw, break and continue. It also applies after a postfix increment.
This minifier keeps a line break wherever its removal could change meaning. That costs a few bytes. It also removes a whole class of bugs that are painful to trace in production.
What this JavaScript minifier does not do
| Feature | Build tools | This tool |
|---|---|---|
| Remove comments and whitespace | Yes | Yes |
| Rename variables | Yes | No |
| Remove dead code | Yes | No |
| Tree shaking | Yes | No |
| Transpile modern syntax | Often | No |
The result is a smaller saving. Expect 20 to 40 percent and not the 60 or 70 a bundler reaches. In return nothing can break. Use a real build tool for a full app. Use this tool for a snippet or an inline script. It also fits code you want smaller without a build step.
Why the tool never renames anything
A rename breaks code that relies on names at run time. Dependency injection by parameter name breaks. Reflection over function names breaks. Error messages lose their meaning. Bugs get hard to trace without a source map.
This tool keeps every name. So a stack trace from the minified file still points at code you recognize. The output also stays readable enough to audit. That matters when you minify code someone else wrote.
Where the real savings come from
Minification is rarely the biggest lever for file size. Remove libraries you no longer use. Load scripts only on pages that need them. Turn on gzip or brotli on your server. Those steps often save more than any minifier.
A safe JavaScript minifier workflow
- Keep your readable script as the source file.
- Make every edit in that source.
- Minify a copy right before you upload it.
- Test the page with the minified copy in place.
- Name the output clearly such as app.min.js.
A clear name tells teammates which file to edit. The next upload would wipe changes made to the wrong copy.
Common JavaScript minifier problems
My code stopped working after I minified it
Check that you copied the full output. Then check the source for a syntax error. The tool keeps meaning but cannot fix broken code.
The saving looks small
Your code has few comments or was already compact. A rename step would save more but this tool skips it on purpose.
My license banner disappeared
Tick the option to keep license banners. Banners start with /*! in most libraries.
Who uses a JavaScript minifier?
Web developers shrink inline scripts. WordPress users trim custom snippets. Email and landing page builders cut file size. Students see how minified code looks.
Your code stays private
The tool works in your browser and uploads nothing. Private code stays on your machine. Need to shrink other files too? Try the CSS minifier, the HTML minifier or the JSON minifier. Want to test a pattern first? The regex tester helps.