JavaScript Minifier
Paste your JavaScript code and get a minified version instantly, using terser to compress it and obfuscate variable names. All processing happens in your browser, without sending your code to any server.
How it works
- Paste or type your JavaScript code into the input panel (a preloaded example lets you try the tool right away).
- Click 'Minify JavaScript' to process it.
- The tool uses terser with the compress and mangle options enabled, which remove dead code, shorten expressions, and rename local variables to shorter names.
- While processing, the button shows a loading icon; terser's analysis can take a moment on large files.
- The original size, minified size, and percentage reduction are shown; copy the result with the copy button.
Use cases
- Reduce the weight of a script before including it in a page without setting up a bundler.
- Compare how much a JavaScript file weighs before and after minifying it.
- Slightly obfuscate local variable names before sharing a code snippet.
- Minify standalone snippets, like analytics scripts or small utilities, before pasting them into a CMS.
Use cases
- Reduce the weight of a script before including it in a page without setting up a bundler.
- Compare how much a JavaScript file weighs before and after minifying it.
- Slightly obfuscate local variable names before sharing a code snippet.
- Minify standalone snippets, like analytics scripts or small utilities, before pasting them into a CMS.
Common mistakes
- Minifying code with syntax errors expecting terser to fix them.terser needs syntactically valid JavaScript to analyze it; if there's an error, the tool shows the exact message instead of an incorrect result.
- Being surprised that variable names changed after minifying (for example, 'message' became 'e').That's mangle in action: it renames local variables and parameters to shorter names to reduce size. It doesn't affect the code's behavior, only its readability; if you need to keep readable names, don't use the minified result for debugging.
- Using the minified code directly to debug errors in production.Minified code is hard to read in the browser's developer tools. Always keep a copy of the original code (or a source map generated by your build) for debugging; use the minified version only for the final deployment.
Frequently asked questions
With the compress and mangle options enabled, terser removes whitespace and dead code, shortens expressions where it's safe to do so, and renames local variables and parameters to shorter names, all without changing the program's behavior.
No. All processing happens locally in your browser using JavaScript. Your code never leaves your device.
terser can't analyze invalid code; the tool catches the error and shows a clear message indicating that the syntax is invalid, instead of failing silently.
That's the effect of the mangle option, which shortens local variable and parameter names (for example, from 'message' to 'e') to reduce file size. Global variables and object properties aren't renamed, so external references don't break.
Alternatives
Build tools like Vite, webpack, or esbuild minify JavaScript automatically as part of the production process, usually with terser or esbuild under the hood. This tool is useful for minifying a one-off script without setting up a full project, for example before pasting it into a CMS or a static HTML template.