About JavaScript Minifier
Paste a script and get the smallest version that still does the same thing, with the size saved shown underneath. Terser removes whitespace and comments, rewrites code into shorter equivalents, drops code that can never run and renames local variables to one or two letters.
Each step can be switched off, and you choose whether top-level names are touched, whether console calls are removed and which comments survive. Licence headers are kept by default. Ask for a source map, inline or as a separate file, so the browser’s developer tools can still show your original code.
How it works
- Terser parses your code into a syntax tree, so it understands scopes and never renames a property or a global another script may rely on.
- Compress rewrites the tree into shorter code that behaves the same: unused code is dropped, constant expressions are folded and statements are joined. Shorten names then renames local variables and parameters.
- Include top-level names extends both steps to top-level functions and variables; turn it on only for code that nothing else calls by name. ES module mode reads import and export and treats the code as strict.
- The work runs in a background worker, and Terser is loaded only when you first minify something.
Questions
Can minifying break my code?
Terser keeps behaviour the same for ordinary code. Code that inspects function names, reads its own source or relies on variables being reachable by name from other scripts can change; for those, turn off Shorten names or leave Include top-level names off.
What does a source map do?
It records where each piece of minified code came from, so developer tools show the original lines and names when you debug. Inline puts it inside the code; Map file shows it separately to save beside the minified file.
Does it handle modern syntax and TypeScript?
Modern JavaScript, including classes, async functions, optional chaining and modules, is read as is. TypeScript and JSX are not JavaScript: convert them first, or the parser stops at the first type annotation or tag.
How large a file can it minify, and is it uploaded?
Up to 2 MB of text, which can take several seconds. Nothing is uploaded: Terser runs in your browser.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.