views:

780

answers:

3

Possible Duplicate:
How can I obfuscate JavaScript?

Can someone please suggest a method to obfuscate the jquery code used in a website. Is it correct to do so from the functionality point of view, i mean will it work fine on all browsers after obfuscation ? Thanks.

+1  A: 

You could minify it (better) or pack it (smaller but slower).

They're not airtight but if you're doing complicated enough things, they'll deter 99.99% of people from reverse engineering.

Both these approaches work well on all modern (IE5+ browsers).

Oli
+3  A: 

I think your best option here is to use one of the more complex minifiers that perform their own unpacking. Names escape me at the moment. Realistically, it's probably a good thing to realize that there is no protecting your javascript from the determined, and as such, there's really not much point giving this too much thought.

spender
+2  A: 

Almost all Javascript minifiers will obfuscate the code to a certain level. All whitespace and superfluous identifiers, brackets will be stripped and variables and function names are replaced by a single character, e.g. var a and function b() instead of var countryDropdown and function changeCountry(). You can use under each JSMIN and YUI Compressor for this.

An example of minified JS can be found here ("full" version here).

This however doesn't prevent users from reverse-engineering the code using smart IDE's with find&replace and renaming tools. So you'd live with it. Minifying is often just done to save the network bandwidth.

If it interests you, we use YUI Compressor here and have good experience with it.

BalusC