Skip to main content
Free tool

JavaScript code obfuscator online: obfuscate JS locally

JavaScript code obfuscation online, your code stays local in the browser

  • Free
  • No account required

Warning. Obfuscation can discourage casual copying and increase reverse-engineering effort. The result is still client-side code that a user can inspect; it does not protect secrets, replace server-side authorization or fix security vulnerabilities.

Techniques
obfuscated.js

These transforms are text heuristics, not a JavaScript parser: console calls inside an expression become void 0 instead of disappearing, and quotes in comments or regex literals can still be misread. The output may parse and still behave differently from the original, so test it before you ship it.

Before you download: do not put API keys, passwords or tokens in client code. Authorization and secrets belong on the backend, and obfuscation does not protect them.

Need a smaller code payload? Add reading friction, then remove unnecessary bytes.
Open the code minifier

A JavaScript code obfuscator online changes selected client-side patterns locally to make quick reading harder. It is not encryption and does not protect secrets, API keys or server authorization.

About the tool

Why obfuscation is not encryption

Obfuscation buys time, not secrecy. It slows down a casual read in DevTools, but a determined reader will recover the logic, because deobfuscators are public and free.

Sensible uses: copying friction for a widget, a demo or front-end game logic, and more work for scrapers. Prices, coupons and API keys are still checked on the server.

Bad uses: hiding malware, dodging ad blockers, or hiding trackers from users.

In practice

Test behavior after transformation

Keep the original file and run tests on the output. Check error handling, console messages and calls from other scripts. Successfully generating code does not prove that the application behaves as before.

Step by step

How to obfuscate JavaScript code before publishing

You obfuscate JavaScript last, on finished code, and only on files you wrote yourself. First make sure the code holds nothing that should stay on the server.

  1. Remove secrets from client code

    Move API keys, passwords and pricing rules to the server. Obfuscation is not encryption, and the browser has to read every string to run the code.

  2. Pick the files you want to protect

    Obfuscate your own logic, such as a widget or a demo. Leave third-party libraries and polyfills alone, because all you gain there is a bigger file.

  3. Paste the code and choose the techniques

    String encoding turns text into \x and \u sequences, and console removal cuts out console.* calls. Both transforms run locally in your browser.

  4. Test the output before you ship it

    The tool uses text heuristics, not a parser. Run your tests or click through the main flows on the obfuscated code, and only then deploy it.

Examples

Example code before and after obfuscation

The examples show the transforms this tool performs.

String encoding
Before
const greeting = 'Hello';
After
const greeting = '\x48\x65\x6c\x6c\x6f';

The browser reads this as the same string, Hello. Typing the variable into the DevTools console shows the original value.

Removing console calls
Before
function save(data) {
  console.log('saving', data);
  return api.post(data);
}
After
function save(data) {
  return api.post(data);
}

Logs with user data disappear from the production console, and the file gets a little smaller.

An API key obfuscation cannot hide
Before
fetch('https://api.example.com/v1/data?key=SECRET_KEY');
After
fetch('/api/data'); // the server adds the key

An encoded key still shows up in the Network tab. The fix is to send the request through your own server, which adds the key on its side.

Common mistakes

Common JavaScript obfuscation mistakes

  • Obfuscation instead of protecting secrets

    The browser has to read every string in client code, so anyone who opens DevTools can read it too. Secrets belong on the server or in short-lived session tokens.

  • Obfuscating the whole bundle with its libraries

    Libraries are public, so obfuscating them hides nothing, while the file grows and runs slower. The javascript-obfuscator authors also advise against obfuscating vendor scripts.

  • Publishing source maps with the code

    A .map file on the server lets DevTools show the source in its original form. If you want to make reading harder, do not publish production source maps.

  • Shipping without a test

    Text transforms can change how code behaves, for example a console call inside an expression turns into void 0. Test obfuscated code like any other change.

  • Heavy techniques in performance-critical code

    Control flow flattening and similar techniques from dedicated obfuscators slow execution down. Keep them out of code that handles scrolling, animation or the first render.

Numbers and sources

JavaScript obfuscation in the documentation

ValueWhat it meansSource
\xNNA hex escape in a JavaScript string is exactly two hexadecimal digits for characters from 0x00 to 0xFF. The browser turns it back into a plain character when it parses the code.MDN, Lexical grammar
15 to 80%How much slower obfuscated code runs according to the javascript-obfuscator documentation, depending on the options.javascript-obfuscator, README
1.5×How much slower code can run after control flow flattening, according to the same documentation.javascript-obfuscator, README
API keysGoogle Cloud advises against putting API keys in client code and recommends passing requests through a server that adds the key.Google Cloud, API keys best practices
pretty printThe Chrome DevTools Sources panel formats minified files by default, and with source maps it shows code in its original form.Chrome DevTools, JavaScript reference

Sources checked:

Glossary

Obfuscation techniques

MMangling
Rename variables and functions to opaque ids (e.g. _0x4a2f). Bundlers and Terser do this; this tool leaves names as they are.
SString encoding
Strings as \x6a\x61\x6e (hex), so literal values are less obvious. This is the technique this tool applies.
DDead code injection
Inject never-run code to grow size and muddy control flow. Found in dedicated obfuscators.
CFControl flow flattening
Turn if/while into a switch and a state table, which can slow execution. Also a dedicated-obfuscator technique.
Security module in Insight

File or code ready? Check the result on the live page

TLS, headers, cookies and exposure, with a score breakdown and a remediation plan.