JavaScript Minifier
Guide: HTML Entities, Formatting and Minifying Explained
132 → 81 characters · 39% smaller
This removes comments and extra spaces. It does not rename variables, so it is safe for any script, but the result is not as small as a full build tool would make it.
Nothing you enter or choose here leaves your device. This tool runs in your browser.
A small before and after
// add numbers
function add(a, b) {
/* sum */
return a + b;
}
const x = add(1, 2);
console.log(`x is ${x}`);function add(a,b){return a+b;}
const x=add(1,2);console.log(`x is ${x}`);That went from 113 characters to 73, about a third smaller. Comments and spaces are gone. The text inside the template string is untouched, and so is the behavior of the code.
What it does and what it leaves
| Removed | Kept exactly |
|---|---|
| Comments | Text inside strings, template strings and regular expressions |
| Extra spaces and indentation | Line breaks where automatic semicolon insertion depends on them |
| Blank lines | Variable and function names |
Notice the line break after the function in the result. JavaScript can add semicolons for you at line ends, and removing a line break in the wrong place can change what the code means. This tool keeps the ones that matter, so code written without semicolons still works.
Why the result isn't the smallest possible
Build tools such as Terser and esbuild also shorten variable and function names, remove unused code and rewrite expressions. That saves much more, often half the file or better, but it needs a proper build step and can occasionally trip over unusual code. This page deliberately only removes comments and white space. It's the safe option for a snippet, a bookmarklet, an inline script or a quick check.
When to use it
- Squeezing a small script into an HTML page or an email.
- Making a bookmarklet fit on one line.
- Cutting a few kilobytes from a file you don't build with a toolchain.
- Checking how much of a file is comments and formatting.
When not to
- On a large app that already goes through a bundler. Let the bundler minify it.
- On your only copy. Keep the readable source and name the minified file differently, like app.min.js.
- As a way to hide code. Minified code is easy to reformat, and it isn't protection.
Test after minifying
- Load the page with the minified file and open the browser console.
- Click through the features the script powers.
- If something breaks, compare with the original. The usual culprits are code that relies on line breaks, or a missing semicolon between statements that were on separate lines.
Your code stays in your browser. For styles and markup, use the CSS minifier and the HTML formatter. To test a pattern from your code, try the regex tester.
Written by Akinrinmade Michael · Updated October 24, 2026
How to use
- 1Paste your JavaScript on the left.
- 2The minified code appears on the right.
- 3Copy the result.
Frequently asked questions
Is my code uploaded?
No. Everything runs in your browser, so what you paste never leaves your device.
Does it rename variables?
No. It only removes comments and extra whitespace, so your code behaves exactly the same.
Why is it not as small as other minifiers?
Build tools shorten variable names too. This tool trades some size for safety.
Will it break code without semicolons?
No. It keeps the line breaks that automatic semicolon insertion depends on.
Does it handle template strings and regular expressions?
Yes. Text inside strings, templates and regexes is left untouched.
Read the guide
Learn how this works and how to get the most from it.
Web & SEO
HTML Entities, Formatting and Minifying Explained
When to escape characters in HTML, how formatting and minifying differ, and how much minifying HTML, CSS and JavaScript really saves.
3 min read
Related tools
CSS Minifier & Beautifier
Compress CSS to save bytes, or format it so it is easy to read.
JSON Formatter & Validator
Prettify, minify and validate JSON, with error line numbers.
HTML / XML Formatter & Minifier
Beautify or minify HTML and XML.
String Escape / Unescape
Escape and unescape strings for JSON, JavaScript, Java, Python, HTML, SQL, regex and CSV.