Menu

JavaScript AST Obfuscator

Transform readable JavaScript into hardened, AST-mangled code. Rename identifiers, encode strings, flatten control flow, and generate ready-to-use configs for javascript-obfuscator.

JavaScript AST Obfuscator Studio 5 Modes
Ready
JavaScript Input 0 chars
Obfuscated Output 0 chars
🔤 Mangle Preview mode. Runs a lightweight AST-style transformation to preview the effect of identifier renaming and string extraction on your code. The real production build should use javascript-obfuscator with the generated config.
Obfuscation is not encryption. Determined attackers can still reverse-engineer the logic with enough time. Never put secrets, API keys, or passwords in JavaScript. Obfuscation slows down casual inspection — it does not prevent it.
Complete Guide to JavaScript AST Obfuscation

What AST Obfuscation Actually Does

JavaScript obfuscation parses your source into an Abstract Syntax Tree (AST), then applies transformations that preserve behavior but destroy readability. Common transformations include:

  • Identifier renaming — calculateDiscount becomes _0x4a2f
  • String extraction — literals move into an encoded array and are retrieved at runtime
  • Control flow flattening — if/else and loops become a switch state machine
  • Dead code injection — unreachable branches confuse static analysis
  • Number encoding — 100 becomes 0x64 or an expression

The result is functionally identical but very difficult to read. Obfuscation is not encryption — with enough time and skill, the logic can still be recovered.

The Five Modes

ModeOutputUse Case
🔤 Mangle PreviewLightweight AST-style rename + string extractionSee the effect before committing to a build config
📦 Production ConfigBalanced javascript-obfuscator configStandard production deployments
🔥 Aggressive ConfigMaximum protection: control flow flattening, dead code, string encodingProtecting valuable algorithms
⚡ Performance ConfigMinimal obfuscation with fast executionPerformance-sensitive code
🐛 Debug ConfigSource maps + reserved namesDebugging obfuscated builds

Using javascript-obfuscator

The generated configs target the industry-standard javascript-obfuscator package. Install it and use the config in a build script:

npm install --save-dev javascript-obfuscator

Then in your build pipeline:

const JavaScriptObfuscator = require('javascript-obfuscator');
const fs = require('fs');

const code = fs.readFileSync('dist/bundle.js', 'utf8');
const result = JavaScriptObfuscator.obfuscate(code, { /* generated config */ });
fs.writeFileSync('dist/bundle.obfuscated.js', result.getObfuscatedCode());

What Obfuscation Cannot Do

  • It cannot protect secrets. API keys, passwords, and tokens in JavaScript are always extractable. Use server-side secrets.
  • It cannot prevent determined reverse engineering. Beautifiers restore formatting, and logic analysis reveals behavior.
  • It cannot replace licensing or authentication. Obfuscation is deterrence, not control.
  • It cannot fix performance. Heavy obfuscation adds runtime overhead — often 15–80% slower.

Performance Reality

Obfuscated code is larger and slower than minified code. String array lookups, control flow flattening, and dead code all add overhead. Use the Performance Config for hot paths, and reserve aggressive obfuscation for logic that runs once or is not performance-critical.

Frequently Asked Questions

Is JavaScript obfuscation secure?
No. Obfuscation is security through obscurity. It makes code harder to read but does not prevent reverse engineering. Never rely on it for secrets or authentication.
Does obfuscation affect performance?
Yes, usually. String decoding, control flow changes, and dead code add runtime overhead. Heavy obfuscation can slow code by 15–80% depending on options. Test your specific workload before deploying.
What is the difference between minification and obfuscation?
Minification removes whitespace and shortens names for size. Obfuscation intentionally makes code incomprehensible through control flow changes, string encoding, and dead code. Minified code is still readable; obfuscated code is not.
Can obfuscated code be reversed?
Partially. Beautifiers restore formatting, string encoding can be decoded, and logic analysis can reveal algorithms. Variable names are lost permanently, but the behavior can be reconstructed with effort.
What is control flow flattening?
A transformation that converts if/else, loops, and branches into a flat switch state machine. This destroys the natural control flow graph, making it very hard to follow the logic.
What is the string array?
String literals are removed from the code and placed in a dedicated array. References become array lookups (often encoded), so strings are not visible in plain text in the source.
Why do I need a seed?
A seed makes the obfuscation deterministic — the same input always produces the same output. This is useful for reproducible builds and caching. Leave it blank for random output each time.
Is my code uploaded to your server?
No. All preview transformations run in your browser. Your JavaScript never leaves your device.
Should I obfuscate vendor scripts?
No. Third-party libraries and polyfills are not your code to protect, and obfuscating them adds size and slowdown for no benefit. Only obfuscate code you own.
What is self-defending code?
An option that makes the code break if it is reformatted or beautified. It adds protection against casual tampering but can cause issues if your build pipeline modifies the output afterward.

Related Tools