JavaScript Minifier & Obfuscator
A JavaScript minifier shrinks a script without changing what it does: it removes comments and whitespace, renames local variables and rewrites code into shorter equivalents. This one runs Terser, the minifier behind webpack and Vite, in your browser. The example below drops from 895 to 579 bytes, 35.3% smaller. Switch to Obfuscate to make code hard to read, or Beautify to make minified code readable again.
Advertisement
How to minify JavaScript
- Paste your code into the left box, upload a .js file, or drop the file onto the box.
- Pick a mode. Minify for the smallest, fastest file; Obfuscate to hide your logic; Beautify to read minified code.
- Check the options. The defaults are safe for any script. If other scripts or inline
onclickattributes call your functions, leave "Rename top-level names" off. - Copy or download the result, and keep the original file for editing. Syntax errors show the line and column; select "Show in code" to jump there.
What the minifier changes
Every example below is produced by the same Terser build that runs in the tool, with the default options.
| Transformation | Before | After |
|---|---|---|
| Comments and whitespace | // Add two numbers | function add(n,d){return n+d} |
| Local names shortened | function greet(userName) { | function greet(e){return"Hi "+e} |
| Constants calculated in advance | var secondsPerDay = 60 * 60 * 24; | var secondsPerDay=86400; |
| Unreachable code removed | function f() { | function f(){return 1} |
| if/return shortened | function check(ok) { | function check(c){c&&start()} |
| debugger removed | function f(a) { | function f(n){return 2*n} |
| Licence comment kept | /*! MyLib v1 | MIT */ | /*! MyLib v1 | MIT */ |
What each option does
| Option | Default | What it does and when to change it |
|---|---|---|
| Rename local variables | On | Shortens names inside functions, the biggest single saving. Turn off only to debug the output. |
| Rename top-level names | Off | Also renames global functions and variables, and inlines them where possible. Safe only when no other script, inline handler or HTML attribute calls them by name. |
| Remove console.* calls | Off | Deletes logging for production. In Obfuscate mode it also silences the console, which the obfuscator otherwise does by default. |
| Remove debugger | On | Removes breakpoints left in the code. |
| Keep licence comments | On | Keeps comments that start with /*! or contain @license or @preserve, which many open-source licences require. |
| Wrap for Blogger XML | Off | Puts the output inside <script>//<![CDATA[ … //]]></script> so it can be pasted into a Blogger theme. |
| Output syntax level | ES2015 | Lets Terser use newer, shorter syntax. It does not convert modern code for old browsers; use a transpiler such as Babel for that. |
| Compression passes | 2 | Each extra pass can find more savings, at the cost of time on large files. |
| ES module | Off | For files that use import or export. Enables strict mode and top-level renaming, which is always safe inside a module. |
| Keep function and class names | Off | Needed when code reads fn.name or constructor.name, for example some frameworks and error reporting. |
| Create a source map | Off | Adds a .map download so browser developer tools can show your original code when debugging the minified file. |
Advertisement
Minify vs uglify vs obfuscate
| Feature | Minify | Obfuscate |
|---|---|---|
| Goal | Smallest, fastest file | Code that is hard to understand |
| File size | Much smaller | Larger than minified, often larger than the original |
| Speed | Same or faster | Slower, especially at high strength |
| Readable after Beautify? | Mostly (local names are lost) | No |
| Use it for | Every production script | Paid widgets, licence checks, logic you do not want copied easily |
"Uglify" is the older name for minifying, after UglifyJS. Terser is its maintained successor and supports modern JavaScript, so "uglify JS" and "minify JS" mean the same thing here.
Obfuscation costs size. The sample script above is 895 bytes; obfuscated it becomes 2,756 bytes at low, 12,122 at medium and 65,034 at high strength. Obfuscation is not encryption: never put passwords or API secrets in browser code.
Benchmarks: jQuery and Lodash
Default options (Terser 5.51.2, two passes), compared with each project's official minified file:
| Library | Original | Official .min.js | This tool | This tool, gzip |
|---|---|---|---|---|
| jQuery 3.7.1 | 285,314 | 87,533 | 86,987 | 30,354 |
| Lodash 4.17.21 | 544,098 | 73,015 | 70,587 | 25,312 |
The minified Lodash was run against the original on chunking, templates, deep merge, sorting, string case and deep equality, with identical results. Each library took about 1.2 seconds on a laptop; the work runs in a background worker, so the page stays responsive.
Using minified JavaScript on Blogger and WordPress
Blogger
Blogger themes are XML, so minified code containing < or && stops the theme from saving. Tick Wrap for Blogger XML, copy the result and paste it in Theme → Edit HTML just before </body>. In a Layout → HTML/JavaScript gadget, paste a normal <script> block instead: gadgets are not parsed as XML.
WordPress
Upload the file to your child theme and load it with wp_enqueue_script() using the defer strategy, or paste the script into a header and footer plugin. If a caching or optimisation plugin already minifies JavaScript, do not minify the same file twice; turn one of them off.
Tip: minify, then add defer to scripts that do not need to run before the page appears. Check PageSpeed Insights before and after.
Frequently asked questions
What does a JavaScript minifier do?
A JavaScript minifier makes a script smaller without changing what it does. It removes comments and whitespace, renames local variables to single letters, calculates constant expressions in advance, removes code that can never run, and rewrites statements into shorter equivalents. This tool uses Terser, the same minifier webpack and Vite use for production builds.
What is the difference between minifying and obfuscating JavaScript?
Minifying makes code as small and fast as possible; the result is hard to read but can be reformatted with a beautifier. Obfuscating deliberately makes code hard to understand by encoding strings, scrambling control flow and adding self-defending code. Obfuscated code is usually larger and slower than minified code, so use it only when hiding logic matters more than speed.
Is obfuscated JavaScript secure?
No. Obfuscation slows down someone reading or copying your code, but any code that runs in a browser can be reversed with enough effort. Never put passwords, API secrets or private keys in front-end JavaScript, obfuscated or not. Keep secrets on a server.
Will minifying break my JavaScript?
Not with the default options, as long as the original code is valid. Terser only applies transformations that keep behaviour the same. Two options need care: Rename top-level names breaks other scripts that call your global functions by name, and Remove console.* calls deletes logging you may rely on. If the result misbehaves, turn those off first.
Does minifying JavaScript help Core Web Vitals?
Yes. Smaller scripts download and parse faster, which helps Largest Contentful Paint when scripts block rendering and Interaction to Next Paint on slower phones. Lighthouse lists unminified scripts under Minify JavaScript. Minify, then load non-essential scripts with defer or async for the biggest gain.
How do I add minified JavaScript to Blogger?
In Theme, Edit HTML, tick Wrap for Blogger XML so the output comes inside a script tag with a CDATA section, then paste it just before the closing body tag. Blogger themes are XML, so a raw less-than sign or && in minified code would otherwise stop the theme from saving. In an HTML/JavaScript gadget you can paste a normal script tag without CDATA.
Is my code uploaded to a server?
No. Terser and the obfuscator are downloaded once and run in a Web Worker inside your browser, so your code never leaves your device. After the first use, the minifier also works offline.
Can I unminify JavaScript?
Partly. Choose Beautify to restore line breaks and indentation so the code is readable again. Original comments and the original names of renamed local variables cannot be recovered, because the minifier removed them. A source map, if you saved one when minifying, maps the minified code back to the original in browser developer tools.
Share this JavaScript minifier
Advertisement
Related tools
Built with Terser and javascript-obfuscator (BSD-2-Clause). Licences.