Short answer: to minify JavaScript online, paste your code into the free JavaScript Minifier, keep Shorten variable names and Compress code switched on, and press Minify. The tool uses Terser, the same engine many build tools use. It removes whitespace and comments, shortens local variable names and drops dead code, often making files 30–60% smaller.
Minify, compress, mangle: what's the difference?
- Whitespace and comment removal: the basic step, safe for any code.
- Compress: rewrites code into shorter equivalents, for example
if(a){b()}→a&&b(), and removes unreachable code. - Mangle: renames local variables and function parameters to single letters. Global names and object properties are left alone, so your code keeps working.
How to minify JS step by step
- Open the JavaScript Minifier.
- Paste your code or open a .js file. Modern syntax (ES2020+, classes, arrow functions, async/await) is supported.
- Choose your options: shorten variable names, compress code, keep
/*! licence */comments. - Press Minify. If there's a syntax error, the tool shows the line and column.
- Copy the result or download it as a file.
Minification happens entirely in your browser, so your source code never leaves your computer.
Why it matters
JavaScript is the most expensive resource on most pages. It has to be downloaded, parsed and executed before a page becomes interactive. Smaller files help Interaction to Next Paint and overall page speed, especially on mid-range phones.
Tips
- Always keep the original. Minified code is very hard to edit.
- Test the minified file before you deploy it.
- Combine this with CSS minification and HTML minification.
- Need to embed a small script or file in JSON? Use the Base64 tool.
Share snippets between your laptop and another computer with copy-paste.online or from the terminal with cpy.
Related: how to minify CSS, how to minify PHP, all free tools.
