Guide

How to obfuscate JavaScript: online or with the CLI

To obfuscate JavaScript, protect a copy of your built .js file, choose a preset, and test the generated output before replacing the original. Start with the free online steps below or copy the npm command for local processing. Then compare the before-and-after examples to understand what each setting changes.

The Short Version

Build → obfuscate a copy → test → ship

Obfuscate the built, minified bundle, never your source tree. Keep the original and its source maps private, and run your tests against the protected copy before it is published.

RenameIdentifiers lose their meaning.
Hide stringsLiterals stop being searchable.
RestructureControl flow stops reading top to bottom.
Quick Start

Obfuscate JavaScript online in four steps

The online tool needs no account and previews supported options on samples up to 32 KB. For files you want to keep on your computer, use the local CLI command alongside these steps.

Free online JavaScript obfuscation

  1. Open the online JavaScript obfuscator. Paste a small script or use “Upload File” for a .js or .txt sample.
  2. Choose Standard to start. Review the selected options and their plan labels before trying Balanced or Maximum.
  3. Click “Obfuscate”. Read the output report, then use “Copy” or “Download” to save a separate protected file.
  4. Run the protected copy in your application. Check the same inputs, user flows, file size and startup behavior before publishing.

Obfuscate a JavaScript file with npm

Install Node.js 18 or later. Save the example below as example.js, then run these commands in its folder. The explicit local engine keeps this free-preset run on your machine.

npx javascriptobfuscator-com --input example.js --output example.protected.js --preset free --engine local
node example.js
node example.protected.js

Both files should print true. Keep the input file; review and deploy the protected copy only after its tests pass. See the CLI and CI guide for project configuration.

What It Is

Obfuscation is not minification, and it is not encryption

A minifier removes whitespace and shortens some names to make files smaller; a formatter puts the structure straight back. Encryption hides data from anyone without the key — but a browser has to execute your code, so it always ends up with everything it needs to run it. Obfuscation sits between the two: the code stays executable, while names, strings and structure are rewritten so that understanding it takes far longer. It raises the cost of copying, tampering with and reverse-engineering your JavaScript. It does not make secrets safe to ship.

Step 0

JavaScript obfuscation example: before and after

Save this complete example as example.js to try the commands above. The transform excerpts below come from recorded runs of the same small function; their byte counts describe those runs, rather than a size guarantee for current presets. Some excerpts omit the invocation or decoder, so use a complete generated file when testing behavior.

example.js
function isLicensed(user) {
  var plan = user.plan;
  if (plan === "pro" || plan === "team") {
    return user.key !== "TRIAL-KEY";
  }
  return false;
}
console.log(isLicensed({ plan: "pro", key: "A1B2" }));

What a reader learns from it

  • The function name says exactly what it guards.
  • The plan names "pro" and "team" are searchable in the shipped file.
  • The trial key "TRIAL-KEY" is right there to copy.
  • The logic reads top to bottom in one pass.

Each transform below removes one of those answers.

Step 1

Rename identifiers (Replace Names, Replace Globals)

Replace Names rewrites local variables and parameters with short generated names. Top-level names are left alone, because other scripts may call them by name; Replace Globals renames those too, consistently across a project. Formatted here for reading — real output is usually a single line.

Replace Names + Short Local Name · 182 bytes
function isLicensed(b)
{
	var a=b.plan;
	if(a=== "pro"|| a=== "team")
	{
		return b.key!== "TRIAL-KEY"
	}
	return false
}
+ Replace Globals · 164 bytes
function a(c)
{
	var b=c.plan;
	if(b=== "pro"|| b=== "team")
	{
		return c.key!== "TRIAL-KEY"
	}
	return false
}
console.log(a({plan:"pro",key:"A1B2"}))

Renaming usually reduces file size without adding a string-decoding wrapper. Its one requirement: any name that code outside this file calls — a public API, a framework callback, a property read off JSON — must be kept, with a variable exclusion rule. The strings, though, are untouched.

Step 2

Move and encode strings (Move Strings, Encode Strings)

Move Strings lifts every literal into one generated table and replaces each use with an index. Encode Strings respells the literals as escape sequences, so a text search of the file for TRIAL no longer finds anything.

Replace Names + Move Strings + Encode Strings · 317 bytes
var _$_2476=["\x70\x72\x6F","\x74\x65\x61\x6D","\x54\x52\x49\x41\x4C\x2D\x4B\x45\x59","\x41\x31\x42\x32"];
function isLicensed(b)
{
	var a=b.plan;
	if(a=== _$_2476[0x0]|| a=== _$_2476[0x1])
	{
		return b.key!== _$_2476[0x2]
	}
	return false
}

Escape sequences stop casual searching, but any JavaScript console decodes them instantly. That is what the next step is for.

Step 3

Encrypt strings (Encrypt Strings)

Encrypt Strings stores the string table in a scrambled form and rebuilds it at start-up through generated decoding logic. It works on the table Move Strings builds, so it needs Move Strings on.

+ Encrypt Strings · 788 bytes (decoder shortened here)
var _$_2476=(function(n,r)
{
	var x=n.length;
	var s=[];
	for(var j=0;j< x;j++)
	{
		s[j]= n.charAt(j)
	}
	/* ... generated shuffle and split logic ... */
	return c
}
)("m%or-Aa1%T2YAeEBKpI%LRt",5638772);
function isLicensed(z)
{
	var y=z.plan;
	if(y=== _$_2476[0x0]|| y=== _$_2476[0x1])
	{
		return z.key!== _$_2476[0x2]
	}
	return false
}

Now neither the plan names nor the trial key appear anywhere in the file, encoded or not. The cost is size — this tiny example more than doubled — and a little start-up work to rebuild the table.

Step 4

Restructure control flow (Code Transposition, Flat Transform)

Code Transposition moves top-level code into a generated wrapper so statements no longer appear in the order you wrote them. Flat Transform then breaks logic apart — here, every comparison becomes a call to a generated helper. Flat Transform needs Code Transposition (or Compressor, which turns it on), and transposition skips code shorter than 256 characters by default, so this example lowered that threshold to show it.

Rename + strings + Code Transposition + Flat Transform · 398 bytes
var a;
(function()
{
	function d(h,i)
	{
		return h!== i
	}
	function e(h,i)
	{
		return h=== i
	}
	var b=["\x70\x72\x6F","\x74\x65\x61\x6D","\x54\x52\x49\x41\x4C\x2D\x4B\x45\x59","\x41\x31\x42\x32"];
	function c(g)
	{
		var f=g.plan;
		if(e(f,b[0x0])|| e(f,b[0x1]))
		{
			return d(g.key,b[0x2])
		}
		return false
	}
	a= c;console.log(c({plan:b[0x0],key:b[0x3]}))
}
)()
Size and Startup

Measure protected bundle size before publishing

String tables, decoding logic and control-flow changes can make a small script larger. Start with the least aggressive preset that meets your requirements, then compare the original and protected files using both raw bytes and the gzip or Brotli sizes your server actually transfers. Test startup and important user flows too.

Compressor is an optional protection setting, separate from HTTP compression. It and some runtime defenses use dynamic evaluation. If your Content-Security-Policy forbids that, choose settings that work with your existing policy and test the generated file. Keep a known-good original for rollback.

Which Options Need Which

Option dependencies, measured

We protected the same input with each of these options on alone and compared the bytes: alone, each left the output unchanged. They only take effect with one of the options in the right-hand column. The online tool switches the prerequisite on for you and reports known skipped or ineffective options; individual effects are not measured.

OptionOnly works withWhy
Flat TransformCode Transposition or CompressorIt restructures the wrapper transposition builds.
Dead Code InsertionCode Transposition or CompressorDead code is emitted into the same wrapper.
Short Local Name, Deep Obfuscation, Replace GlobalsReplace NamesThey change how the renaming pass names things.
Encrypt Strings, Move MembersMove StringsThey work on the string table Move Strings creates.
Three Ways To Run It

Online, in your build, or on your desktop

Online tool

Paste or upload a sample and pick a preset. No account; samples up to 32 KB, and supported paid options can be previewed before you buy. Best for trying settings.

Open the online obfuscator ›

npm CLI in your build

Protect the built output after your bundler runs. The local CLI runs free options on your own machine — no source is uploaded and the local CLI has no file-size cap. Paid options run on the hosted service and need a plan.

npm install --save-dev javascriptobfuscator-com
npx javascriptobfuscator-com --preset free --input dist --output dist-protected --engine local

CLI and CI guide ›

Desktop app

Whole folders in one batch, and JavaScript embedded in HTML, PHP, ASP, ASPX or JSP protected in place. Local Standard keeps basic ES5 files entirely offline.

Download for Windows ›

Before You Ship

Test the protected JavaScript before publishing

  • Run your test suite against the protected output. A file that protects without errors has not yet been shown to work. See the compatibility checklist.
  • Keep names other code depends on: public APIs, framework hooks, and keys read from JSON or the DOM.
  • Check your Content-Security-Policy if you use the Compressor or runtime defences.
  • Never deploy source maps next to protected files; they map the output straight back to your source.
  • Keep the identifier map from each build, privately, to decode production stack traces.
What It Cannot Do

Limits worth knowing up front

  • Secrets are still secrets. An API key in front-end code is readable however it is protected; keep it on the server.
  • Checks belong on the server. A licence or payment check that only runs in the browser can be bypassed by whoever controls the browser.
  • It raises cost, not walls. Determined analysis of a protected file is slower and harder, not impossible.

Our failure modes guide covers what breaks and why.

Frequently Asked

JavaScript obfuscation questions, answered

How do I obfuscate JavaScript online?

Open the online JavaScript obfuscator, paste or upload a small JavaScript sample, choose a preset, and click Obfuscate. Save a separate protected copy and test it before publishing. No signup is needed for online samples up to 32 KB. Follow the four steps above.

Can obfuscated JavaScript be reversed?

It can be analysed, because the browser has to run it. Formatters restore whitespace, but not the original names, string layout or control flow. Obfuscation raises the cost of understanding and reusing the code; it is not a security boundary.

Does obfuscation make JavaScript bigger or slower?

Renaming often reduces size, while string tables, encryption and control-flow transforms can increase it. Compare raw and gzip or Brotli sizes for your actual bundle, and measure startup and important user flows before choosing stronger settings.

Should I minify before or after obfuscating?

Build and minify first, then obfuscate the bundle. Minifying obfuscated output can undo or break transforms that depend on the generated structure. More in minification vs obfuscation.

Why did an option not change my output?

Some transforms only work with another one on — see the dependency table above. Code Transposition also skips code shorter than 256 characters by default, so a very small sample may show no change from it.

Can I obfuscate JavaScript for free?

Yes. The online tool needs no account and previews supported options on samples up to 32 KB. With no account, the npm CLI runs the free options (renaming, string encoding and moving) on your own machine: nothing is uploaded and there is no size cap. The paid transforms need a plan.

Try It

Run this example yourself

Paste the 8-line example into the online obfuscator, switch presets, and read the report under the output: it lists what was applied, which options are paid, and anything that had no effect.

JavaScript obfuscation techniques explained · What is JavaScript obfuscation? · Obfuscate JavaScript inside an HTML file · Protecting JavaScript (overview) · Online code obfuscator · VM bytecode obfuscation · Obfuscation glossary