How to minify JavaScript with this tool
- Paste your code into JavaScript input, or click Open file to load a .js file. The page opens with a short example so a result shows straight away.
- Keep Shorten variable names ticked to rename local variables and function parameters. Keep Compress code ticked to let the minifier simplify the code itself, for example by folding constants and removing unreachable branches. Clear it to keep your statements as written.
- Tick Treat as ES module if the file uses import, export or top-level await. Keep Keep license comments ticked to retain comments that start with
/*!or contain @license or @preserve. - Read the result and the size line under the boxes, then use Copy or Download (saved as script.min.js).
How the minifying works
Minifying is done by Terser (version 5.51.2, BSD-2-Clause licence), the same engine many build tools use, running in your browser. It parses your code into a syntax tree, the way a browser would, rather than stripping spaces with search and replace. That is why strings, template literals, regular expressions and code written without semicolons all survive: the tree knows where each statement ends. The compress step then rewrites the tree, the mangle step gives local names short replacements, and the printer writes the result with only the spaces and semicolons that are needed. Sizes are counted in UTF-8 bytes, which is what a file or a download uses, and do not include gzip.
Worked example
With the default settings (shorten names on, compress on, license comments kept) the example input
// Add two numbers
function add(a, b) {
/* simple addition */
return a + b;
}
console.log(add(2, 3));
becomes
function add(d,n){return d+n}console.log(add(2,3));
The size line reads "106 bytes → 51 bytes (51.9% smaller)". Both comments are gone, the parameters a and b became d and n, and the top-level name add stayed because another script could call it.
Limits and edge cases
- Only plain JavaScript is accepted. TypeScript and JSX must be compiled first. A syntax error is reported with its line and column, and top-level await needs Treat as ES module.
- Top-level names are kept unless Treat as ES module is ticked. In module mode the tool also renames, and drops when unused, names that are not exported, so tick it only for real modules.
- Property names such as
user.firstNameare never renamed, and names are left alone in code that uses eval or with. - Code that depends on function names or on a function's source text can behave differently once names are shortened. Clear Shorten variable names for such files.
- No source map is produced, so keep your original file. Above 300,000 characters, click Minify instead of waiting for live updates.
- The first use downloads about 1.1 MB of minifier code from jsDelivr. Your code is never sent anywhere.
Frequently asked questions
Will minifying break my JavaScript?
Not for normal code. The minifier keeps the program's behavior and only changes how it is written. Problems come from code that relies on variable or function names, so test the minified file, and clear Shorten variable names if something misbehaves.
Can it minify JavaScript that has no semicolons?
Yes. Because the code is parsed, the minifier inserts the semicolons the language needs, so a file written in the no-semicolon style comes out valid.
How much smaller will my file get?
It depends on your code. Comments, long names and generous spacing shrink the most, while code that is already minified shrinks little or not at all. The size line shows the exact before and after in bytes.
Is minified code the same as obfuscated code?
No. Minifying makes a file smaller and happens to make it harder to read, but anyone can restore the layout with a beautifier. It does not hide what the code does, so never rely on it to protect secrets.
To read minified code again, use the JavaScript beautifier. Shrinking the rest of a page? Try the CSS minifier and the HTML minifier.
Sources: Terser 5.51.2 documentation, minify options (terser.org/docs/options).