JavaScript Minifier — Smaller JS Files with Terser
Paste your JavaScript and shrink it with Terser: whitespace, comments and unreachable code are removed, while variable names stay readable. Your code is processed in your browser and never uploaded.
Related tools
- Code Formatter Beautify and format HTML, CSS, JavaScript, XML, SQL code. Beautify or minify with customizable indentation and auto-format as you type.
- SQL Formatter Format SQL queries with one clause per line, upper-case keywords and indented joins, conditions and subqueries.
- HTML Formatter Beautify messy or minified HTML with clean indentation of 2 spaces, 4 spaces or tabs, or minify it again.
- CSS Minifier Minify CSS by removing comments and whitespace, or beautify minified CSS again. Safe for string values.
Features
- Minify JavaScript with Terser 5.31
- Removes whitespace, line breaks and all comments
- Drops unreachable code and unused local variables
- Variable and function names stay unchanged and readable
- Copy the result or download it as a .js file
- Your code is processed in your browser, nothing is uploaded
What a JavaScript Minifier Does
Browsers do not need indentation, line breaks or comments to run a script. A JavaScript minifier removes everything that only exists for human readers, so the file travels faster over the network and is parsed sooner. Typical steps are:
- Whitespace and comments: indentation, blank lines and comments disappear.
- Compression: the code is rewritten into a shorter equivalent, for example by merging declarations or dropping braces that are not needed.
- Dead code: branches that can never run and local variables that are never used are removed.
- Renaming (mangling): many minifiers also shorten local names such as
totalPricetot.
This tool does the first three. Renaming is deliberately switched off, see below.
How This Minifier Handles Your Code
The first time you minify JavaScript, the page loads Terser 5.31.0 from the jsDelivr CDN. The script tag carries a Subresource Integrity hash, so the browser refuses the file if it was altered. After that, minification runs entirely in your browser; your code is never sent anywhere.
- Terser's
compressstep is on, including dead code removal. console.*calls anddebuggerstatements are kept.- Names are not mangled, so the output stays readable and error messages still show your own names. The file is therefore larger than with full mangling.
- All comments are removed, including
/*! … */license banners. - No source map is created.
If your code has a syntax error, there is no output: you see Terser's parser message instead. If Terser cannot be loaded (offline, CDN blocked), the tool shows an error and does not fall back to a simpler method; just try again once the connection works.
Example
/*! my-lib v1.0 | MIT */
// Sum up all prices
function total(items) {
const debug = false;
let sum = 0;
for (const item of items) {
sum += item.price;
}
if (debug) {
console.log("sum", sum);
}
return sum;
}
console.log(total([{ price: 2 }, { price: 3 }]));Minified, this becomes a single line. The two comments are gone, including the license banner. Because debug is always false, Terser drops the variable together with the whole if block. The braces around the one-line loop body disappear too. The final console.log stays, and total, items, sum and item keep their names.
Tips Before You Ship
- Keep the original. Minified code is hard to edit. Always change the source file and minify again; never edit the output.
- Source maps for debugging: in a build pipeline, let your bundler or the Terser CLI write a source map so browser dev tools can show the original lines. This tool is meant for quick, one-off files.
- License comments: if a license requires its notice, add the banner back to the top of the output.
- Top-level code stays: unused global functions and variables are kept, because another script on the page might use them.
- Syntax support: ES modules (
import/export) and modern syntax work as far as Terser 5.31 supports them. TypeScript and JSX are not JavaScript and must be compiled first.
Useful Resources