Hiding/Encoding my javascript code
Can I hide my javascript code on the client side??? Or some way make it non-开发者_JAVA百科readable not by users but by hackers as well??
Well it's not a complete solution, but you could minify your javascript to make it less human readable.
Wikipedia article on minification: http://en.wikipedia.org/wiki/Minification_(programming)
Online tool to minify javascript: http://www.refresh-sf.com/yui/
There is no way. It can't be encrypted because the browser has to execute it and he doesn't know how to decrypt.
Best is to minify/obfuscate (see anax) in order to let users don't bother trying to read the code. If someone wants it badly, he eventually get it. The time to do so is high, and hopefully this will dis-encourage users.
You can go from really cheap (adding lots of CR into the start of the HTML document) to not-so-cheap tricks (Javascript minify / obfuscate), but in reality nothing will prevent a half-descent user to read your code.
Have a look at this SO question for possible ways to obfuscate your script:
How can I obfuscate (protect) JavaScript?
精彩评论