views:

53

answers:

3

How can I protect my implemented JS methods from user? So that no one could copy these methods. Normally, User can see JS methods in firebug easily. I want to hide methods in firebug also. Is there any trick to hide methods from users?

Note: I don't want to use Eval method. so please don't suggest me to eval based tricks

+2  A: 
  1. try packing the code/minifiying it

google closure compiler is a good start

there is also a YUI lib that you can use and many others.

This will make your code pretty much impossible to debug in firebug.

There is no full proof way though to stop users for mucking with your code, since it does run on the client side by definition.

  1. Another thing you can do is put the methods you want to hide inside of a closure, so that the user cant simply run someMethod() from firebug and have it execute code.
mkoryak
+3  A: 

There is no way to hide your code from the user. If the browser can see it, than Firebug can see it. Using a minifier/packer used to be a way to make it harder to get to the data, but sites like http://jsbeautifier.org/ have the ability to take packed code and make it pretty.

Short answer is there is no way of hiding code. If it was possible, Microsoft, Google, Yahoo, Etc would be hiding their code.

Think of JavaScript, HTML, and CSS as open source since the source code is just one click away.

epascarello
+1 for reverse engineering using jsbeautifier
Brij
+1  A: 

The only way to efficiently protect your code is to never send it to the client:
Put your “secret” methods on the server and make them ajax-callable from the client.

Edgar Bonet