How to use the JavaScript Minifier
- 1Paste your JavaScript.
- 2Choose compress and mangle options.
- 3Copy or download the minified code.
About the JavaScript Minifier
JavaScript is often the biggest cost on a page: it must be downloaded, parsed and executed. Terser, the industry-standard minifier, compresses and mangles code for the smallest output.
Supports modern syntax including classes, async/await and optional chaining.
When to use the JavaScript Minifier
Preparing a standalone browser script
When a page uses a standalone script maintained outside a build process, create a smaller delivery copy before deployment. Paste the JavaScript, select Compress and Mangle names as appropriate, and inspect the resulting byte savings. Download script.min.js and exercise the page's interactions using that exact file before publishing it.
Comparing compression and name mangling
If you need to balance compact output against easier inspection, run the same source with different combinations of the two switches. Compression can transform code, while mangling shortens eligible names. Comparing the generated versions helps you choose an appropriate delivery copy without changing the readable source you maintain during development.
Checking a revised widget script
A small embedded widget may need a compact script after a feature update. Run the revised source through the minifier and watch for a syntax error before copying the output. Then test initialization, event handlers, and any public integration points in context; successful minification alone does not verify the widget's behavior.
Tips and best practices
- Change one option at a time when investigating unexpected output. Keeping the same input makes differences caused by compression or name mangling easier to isolate.
- Avoid treating minification as a way to hide secrets. Smaller variable names do not prevent someone from reading shipped code or extracting embedded credentials.
- Preserve required attribution separately because the generated JavaScript removes comments. Check the original library's license terms before distributing a comment-free version of its code.
- Do not expect imports to be resolved or multiple files to be bundled. Supply the code you intend to minify and handle project assembly separately.