JavaScript Minifier
Paste JavaScript, choose how far to go, and get smaller code from terser, run in this page. Syntax errors are shown with their line and column.
Paste JavaScript, then press Minify.
Your code stays on your device: terser runs in this page, and nothing is sent or saved. Up to 1 MB.
Smaller JavaScript, made by terser in your browser
Minified JavaScript loads and parses faster, which matters most on phones. This page runs terser, the minifier many build tools use, directly in your browser. It suits a single script for a small site, a bookmarklet or a snippet you embed; for a whole project, a build tool on your computer does the same job on every change.
How to use it
- Paste your code into the box.
- Choose the settings. The defaults are a safe start for most scripts.
- Press Minify. The first time, the minifier loads from this site, which takes a moment.
- Copy the result or download it as a .js file, then test it before you ship it.
What the settings do
- Compress rewrites code into shorter equivalents: unused code goes, constant expressions are worked out, and if statements can become shorter expressions.
- Rename local names replaces names inside functions with short ones. Global names stay, since other scripts may use them, unless you mark the code as an ES module.
- ES module tells terser the code is a module, which also allows import, export and await at the top level.
- ECMAScript version lets terser use newer syntax, such as arrow functions, where it saves space. Choose the oldest version your visitors’ browsers need.
When something goes wrong
If your code can’t be read, nothing is minified. You’ll see the message with its line and column, and the lines around it with a mark under the spot. Fix it in your original file and run it again.
Good practice
- Start with the defaults, and turn on ES module only for code that really is a module.
- Test the minified file in the browsers your visitors use before you replace the original.
- Save it as name.min.js next to the readable file, so it’s clear which one to edit.
Good to know
- No source map is made, so error messages from the minified file point to its single long line. Keep your original for debugging.
- Up to 1 MB: larger files can keep a browser tab busy for a long time.
- Shrinking the rest of a site? The Image Compressor handles pictures, often the largest files.