Is it possible at all?
Thanks!
You can obfuscate it, but there's no way of protecting it completely.
example obfuscator: http://www.javascriptobfuscator.com/Default.aspx
No, it's not possible. If it runs on the client browser, it must be downloaded by the client browser. It's pretty trivial to use Fiddler to inspect the HTTP session and get any downloaded js files.
There are tricks you can use. One of the most obvious is to employ a javascript obfuscator.
Then again, obfuscation only prevents casual snooping, and doesnt prevent people from lifting and using your code.
You can try compiled action script in the form of a flash movie.
One of the best compressors (not specifically an obfuscator) is the YUI Compressor.
The only safe way to protect your code is not giving it away. With client deployment, there is no avoiding the client having access to the code.
So the short answer is: You can't do it
The longer answer is considering flash or Silverlight. Although I believe silverlight will gladly give away it's secrets with reflector running on the client.
I'm not sure if something simular exists with the flash platform.
JavaScript is a scripting language and therefore stays in human readable form until it is time for it to be interpreted and executed by the JavaScript runtime.
The only way to partially hide it, at least from the less technical minds, is to obfuscate.
Obfuscation makes it harder for humans to read it, but not impossible for the technically savvy.
If you have anything in particular you want to hide (like a proprietary algorithm), put that on the server, or put it in a Flash movie and call it with JavaScript. Writing ActionScript is very similar to writing JavaScript, and you can communicate between JavaScript and ActionScript. You can do the same with Silverlight, but Silverlight doesn't have the penetration Flash does.
However, remember that any mobile phones can run your JavaScript, but not Silverlight or Flash, so you're crippling your mobile users if you go with Flash or Silverlight.