How can I hide my JavaScript functions so that nobody can steal them? [duplicate]
Possible Duplicate:
How to prevent your JavaScript code from being stolen, copied, and viewed ?
I have a user form that has a submit button. Once clicked, a certain JS function is called and the code does something. I want to hide this so that nobody can see it. What is the best way to do this? I am not using any JS libraries, it is just code that I wrote myself.
Thanks!
you can always obfuscate and minify your code so that it's only single letters and such. There is no real way someone can't steal your javascript, but that is the best way you can "hide" it so people can' really read your variable names, etc.
Instead of using JavaScript, you could submit the form to the server, and run the same code using PHP or something. If you're manipulating something on the page based on what happens in the JS function, you could do the following:
- When the form is submitted, cancel with JS (you're probably already doing this)
- Get all the information from the form, do everything that you're comfortable doing on the client side
- Make an AJAX call, sending the necessary data to the server, where your now-confidential function can run
- Return whatever information you need to return back to the client and make whatever changes you need to make
You can't. This is anathema to the entirety of the web. For the same reason you can't stop picture theft.
What you could do to help prevent it is not only obfuscation as mentioned before, but also prevent outright downloading, require referrer headers and the like.
In the end tho, if you expose it via HTTP, someone else will be able to steal it. End of story.
You can't entirely.
The best option is to obfuscate it, but then it is still delivered to the client's browser, and they can read it (albeit obfuscated).
There are other ways to obscure it such as serving it via a custom handler that requires some kind of authentication, but ultimately its security through obscurity which is no security at all.
精彩评论