how to hide javascript code [duplicate]

Possible Duplicate:
How can I obfuscate JavaScript?

Hello!

Is it possible to hide JS code? How? I read somewhere a technique like: take JS to external file, and use js-encrypt.

I know that is impossible to hide from all eyes, but...

Thank you.


It is not possible to hide Javascript from the user, since their browser needs to download it to execute it. The only other option is obfuscation.


You can run your private JavaScript server side e.g. using ASP JScript.NET

<% WebService Language="JScript" Class="MyClass" %>

You can put the hidden functionality on the server and call it via AJAX in the non hidden part of the code on the client.

you can also use

<script runat="server">

or if you're not using a Microsoft platform you might consider Mozilla Rhino


As you can take someone else's code and try to encrypt it, same goes for others who can take your code. The only solution that i think is to obfuscate your javascript code so that it becomes little difficult for others to grasp but there again there decryptors available so no real solution as of what i know has come about so far.