Encrypt or Obfuscate jQuery & JavaScript code
JavaScript Obfuscation is a way to darken or encrypt your JavaScript files without changing their functioning. This way, normal users won’t be able to edit and modify your JavaScript code.
Obfuscation basically means making code unreadable by using advanced algorithms without changing it’s functionality or anything else. But how to do that? This article features some resources for you to obfuscate your JavaScript.
JavaScript Obfuscation: Example
Take a look at the below given simple 3-line (absolute rookie-level) JS code:
function foo(x, y) { alert(x+y); }
Now, see it’s obfuscated version:
eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('2 4(1,0){3(1+0)}',5,5,'y|x|function|alert|foo'.split('|'),0,{}))
Who knows what’s behind this obfuscated code and what it is doing? This is how obfuscation helps to make your code unreadable to normal user, reason may be anything, source protection, making others confused etc.
Tools to Obfuscate JavaScript Online
These tools are based on direct, URL or file input to obfuscate JavaScript online. Pretty easy to use, just input, submit the form and get the obfuscated code. Easy!
Software and scripts to Obfuscate JavaScript
The below given programs or scripts may help those who want minification and obfuscation of their JavaScript files at once, without editing them one-by-one manually.
I was using a Firefox browser add-on to obfuscate my scripts, but that is permanently removed from Firefox add-on gallery some days ago. I’ll be adding Firefox add-ons and Chrome extensions for the same if I found some handy ones. Hope you enjoyed the article.