How to use the JavaScript Minifier tool
- Add your scriptPaste the code, or press “Open file” to load a .js or .mjs file.
- Select optionsCompress, mangle variable names, treat the input as an ES module and keep licence comments.
- Run the minifierPress “Minify JavaScript”; any syntax error is reported with its line and column.
- Copy or saveCopy the minified code or download it as a .min.js file.
JavaScript minifier features
- Proven engineBuilt on Terser, the minifier inside webpack, Vite and many other toolchains.
- Name manglingLocal variables and functions are renamed to short identifiers like a and b.
- Dead code eliminationUnreachable branches are dropped, expressions simplified and declarations merged.
- Modern JavaScriptHandles classes, arrow functions, async/await, optional chaining and ES modules.
- Precise errorsSyntax mistakes are pinpointed by line and column so you can fix them fast.
Why minify JavaScript?
Scripts are frequently the most expensive part of a web page to download, parse and execute. Minification cuts file size, often by 30–60% for readable source code, so JavaScript arrives sooner and pages become interactive faster, particularly on mobile devices.
What each minify option does
- Compress rewrites code more efficiently, removing unreachable sections, folding constants and shortening conditions.
- Shorten variable names renames locals, so
discountRatemight becomerinside a function. - Also shorten top-level names renames global functions and variables too, which is only safe if no other script depends on them.
- ES module enables
import/exportand strict mode. - Keep license comments preserves
/*! … */and@licenseblocks.
JavaScript minification best practices
- Keep your source. Minified output is hard to read, so always edit the original and minify again.
- Test the result, especially when shortening top-level names, which can break code other scripts call by name.
- Enable compression. Gzip or Brotli on the server add a further saving on top of minification.
- Use a bundler for large projects. Multi-file apps are better served by Vite or webpack, which minify as part of the build.
How this tool works
Terser, released under the BSD licence, is fetched from a public CDN the first time you minify and then runs completely in your browser, so your code is never uploaded. You might also like the CSS Minifier, the HTML Minifier and the JSON Formatter.
Frequently asked questions
How can I minify JavaScript online?+
Paste your code or open a .js file, pick the options and press “Minify JavaScript”, then copy or download the output.
Does minified code behave the same?+
Yes, with default settings. Test thoroughly if you enable “Also shorten top-level names”, because other scripts may rely on global names.
Is modern JavaScript supported?+
Yes. Terser understands ES2020+ syntax, including classes, async/await, optional chaining and ES modules.
Why am I seeing a syntax error?+
The code has invalid JavaScript at the line and column shown. Fix it and try again; TypeScript and JSX need compiling first.
Does my code get uploaded?+
No. Terser is downloaded into your browser and your code is processed locally.