Welcome to our tutorial, now I am going to explain one of the best ways to protect your javascript code.

By the end of this tutorial you will be aware of:
- Why It Is Important to Protect Your JavaScript Code ?
- What is Obfuscation ?
- Javascript Obfuscation Techniques
- JavaScript Obfuscation Tools
- Does the Best JavaScript Obfuscator Can Be Reverse-Engineered ?
- Google Javascript Obfuscator
Why It Is Important to Protect Your JavaScript Code ?

JavaScript is a client-side language which make it visible to all browsers. This unfortunately means that it is visible to anyone who wants to see your code and potentially steal it. Therefore, you may need to encrypt your code and make it unreadable using one of the code protection ways which obfuscate the code using base algorithms. This process allow the developer to achieve the next main objectives:
- Making code harder for anyone to copy and paste parts of code.
- Reducing file size hence saves outgoing and incoming bandwidths for you and your visitors, respectively. Also, improving the loading speed for better SEO.
What is Obfuscation ?

Obfuscation is one of the best ways to protect your javascript code. It makes your code unreadable using complicated algorithms to apply encryption and minification, which as well reduces the size of your files for better loading speed. Meanwhile, the obfucated code will work like your original code.
Javascript Obfuscation Techniques
Javascript obfuscation utilizes five main techniques as follow;

- Minification: removes unnecessary spaces, comments and line breaks.
- Encryption: converts strings to encoded form.
- Rearrangement: alters sequences of script in random manner.
- Injection: adds small blocks of code to serve monitoring, domain locking, or redirection and expiration date setup.
- Replacement: supersedes original names of variables and functions with other random ones. Times, converts them to strings and run code using the eval function which is not preferable.
JavaScript Obfuscation Tools
There are a number of JavaScript obfuscation tools that are freely available;
- WB JavaScript Obfuscator: WhiteBoxes dot tk provide an online and majorly free javascript obfuscator which gathers all the best features to protect your javascript code. This is what I use all time.
- Google Closure JS Compiler: It is a natural tool for the production environment which optimize, compress, and minify your code.
- YUI Compressor: Yahoo!'s JavaScript compressor is an open-source Java-based tool which condense the code to mainly improve the loading time, also provide low level of obfuscation but works relatively well. As necessary, Compressor will replace function names, eliminate whitespace, and alter variables.
- JSMin: is just a minification tool by Douglas Crockford that focus to minify your JavaScript source for faster loading in browsers. Crockford's developed JSMin not to obfuscate, but to uglify.
- Other JavaScript Obfuscator: they are web-based tool that try to obfuscate your code by encoding it.
Does the Best JavaScript Obfuscator Can Be Reverse-Engineered ?

In short, yes, but even a super intellegent developer will take days up to weeks to reverse-engineer some blocks of your code. Therefore, it's more worth to start his own code than sticking to know how to re-use others code.
Google Javascript Obfuscator
Nothing exists up to Dec 5, 2017 is called so. And, the only tool provided by google is the one explained above titled "Google Closure JS Compiler".
Go to Recommended JavaScript Obfuscator >>
Thank you for reading the above article. Please let us know your comments below.
References:
- Practical Experience
Related Articles
- How to Secure your JavaScript Code from being Copied by Competitors | Javascript Tutorial
- How to Promote JavaScript To Speed Your Website Loading Time For Higher SEO Performance | Javascript Tutorial
- Best Way To Loop Through Javascript Array Of Objects | Javascript Tutorial
- Best Way To Create Javascript Array Of Objects | Javascript Tutorial
- Best Way To Loop Through Javascript Array | Javascript Tutorial
- How to Create Javascript Multidimensional Array | Javascript Tutorial
Latest Articles
- What are Php Arithmetic and Comparison Operators ? | Php Tutorial
- What are Php Variables and Types ? | Php Tutorial
- How to write your first php web page with code example | Php Tutorial
- Introduction to Php Learning Course | Php Tutorial
- How to Secure your JavaScript Code from being Copied by Competitors | Javascript Tutorial
- How to Promote JavaScript To Speed Your Website Loading Time For Higher SEO Performance | Javascript Tutorial