All tools

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.

Updated Runs in your browser; nothing is uploadedWhat each option does

Minify JavaScript

Advanced options

Paste, type, or drop a .js file here. Ctrl+Enter runs it.

895 B → 579 B (35.3% smaller)

Advertisement

How to minify JavaScript

  1. Paste your code into the left box, upload a .js file, or drop the file onto the box.
  2. Pick a mode. Minify for the smallest, fastest file; Obfuscate to hide your logic; Beautify to read minified code.
  3. Check the options. The defaults are safe for any script. If other scripts or inline onclick attributes call your functions, leave "Rename top-level names" off.
  4. 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.

Terser transformations with before and after
TransformationBeforeAfter
Comments and whitespace// Add two numbers
function add(first, second) {
return first + second;
}
function add(n,d){return n+d}
Local names shortenedfunction greet(userName) {
const message = "Hi " + userName;
return message;
}
function greet(e){return"Hi "+e}
Constants calculated in advancevar secondsPerDay = 60 * 60 * 24;var secondsPerDay=86400;
Unreachable code removedfunction f() {
if (false) { console.log("never"); }
return 1;
}
function f(){return 1}
if/return shortenedfunction check(ok) {
if (!ok) {
return;
}
start();
}
function check(c){c&&start()}
debugger removedfunction f(a) {
debugger;
return a * 2;
}
function f(n){return 2*n}
Licence comment kept/*! MyLib v1 | MIT */
var x = 1;
/*! MyLib v1 | MIT */
var x=1;

What each option does

Minifier options
OptionDefaultWhat it does and when to change it
Rename local variablesOnShortens names inside functions, the biggest single saving. Turn off only to debug the output.
Rename top-level namesOffAlso 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.* callsOffDeletes logging for production. In Obfuscate mode it also silences the console, which the obfuscator otherwise does by default.
Remove debuggerOnRemoves breakpoints left in the code.
Keep licence commentsOnKeeps comments that start with /*! or contain @license or @preserve, which many open-source licences require.
Wrap for Blogger XMLOffPuts the output inside <script>//<![CDATA[ … //]]></script> so it can be pasted into a Blogger theme.
Output syntax levelES2015Lets Terser use newer, shorter syntax. It does not convert modern code for old browsers; use a transpiler such as Babel for that.
Compression passes2Each extra pass can find more savings, at the cost of time on large files.
ES moduleOffFor files that use import or export. Enables strict mode and top-level renaming, which is always safe inside a module.
Keep function and class namesOffNeeded when code reads fn.name or constructor.name, for example some frameworks and error reporting.
Create a source mapOffAdds a .map download so browser developer tools can show your original code when debugging the minified file.

Advertisement

Minify vs uglify vs obfuscate

Comparison
FeatureMinifyObfuscate
GoalSmallest, fastest fileCode that is hard to understand
File sizeMuch smallerLarger than minified, often larger than the original
SpeedSame or fasterSlower, especially at high strength
Readable after Beautify?Mostly (local names are lost)No
Use it forEvery production scriptPaid 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:

Bytes, smaller is better
LibraryOriginalOfficial .min.jsThis toolThis tool, gzip
jQuery 3.7.1285,31487,53386,98730,354
Lodash 4.17.21544,09873,01570,58725,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.

Advertisement

Built with Terser and javascript-obfuscator (BSD-2-Clause). Licences.