JavaScript Minifier
Make a script smaller for faster loading. Choose how aggressive the minification is, and keep licence comments.
or drop a file here · .js, .mjs, .txt · up to 20 MB
About the JavaScript Minifier
A script written for people is full of descriptive names, comments and whitespace that a browser does not need. Minifying removes them and rewrites the code in shorter but equivalent form, so pages download and start faster. This page uses Terser, the minifier inside many popular build tools, running in your browser.
When to use it
- You add a hand-written script to a static site, a Shopify theme or a WordPress footer.
- You are building a bookmarklet and need it as short as possible.
Worked example
After Try an example fills in the cart-total script, press Minify JavaScript with the default options. The comment disappears, the function’s parameter and local variables are renamed to single letters, the loop body loses its braces, and the whole script fits on one line. Names visible to other scripts, such as cartTotal and cart, are kept, because another script on the page might use them. The size label shows the saving.
Options explained
- Shorten variable names renames local variables and parameters. Turn it off if code relies on function names at run time, for example in error messages or with eval.
- Optimise code applies safe rewrites: removing unreachable code, joining declarations and simplifying expressions.
- Keep licence comments keeps comments starting with
/*!or containing an@licensetag. - ES module is for code that uses import or export. In a module, top-level names are private, so Terser can shorten them as well.
Is it safe?
Terser is a mature, widely used minifier, and it only makes changes intended to keep behaviour identical. Code that reads its own source text can still be affected. Test the result before deploying.
Limits
- Only JavaScript is accepted. TypeScript and JSX must be compiled first.
- A syntax error is shown with its position and nothing is produced.
- Minifying is not protection: anyone can reformat the result with the JavaScript formatter.
- For styles and markup, see the CSS minifier and HTML minifier.
How to use JavaScript Minifier
- Paste JavaScript or open a .js file.
- Choose the options. Tick ES module if the code uses import or export.
- Select Minify JavaScript, check the size saved, then copy or download the result.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
Will the minified code behave the same?
It should. Terser is widely used in build tools and only applies changes that keep the behaviour the same. Code that depends on function names or uses eval may be affected by name shortening; turn that option off in that case.
What is the ES module option?
Tick it when the code uses import or export. It also lets Terser shorten top-level names, which is safe in a module.
Does it support TypeScript or JSX?
No. Compile TypeScript or JSX to JavaScript first.