Possible Duplicate:
How can I obfuscate JavaScript?
Is there a way to protect JS file from being opened and copied. Perhaps it can be encoded? Just curious.
Possible Duplicate:
How can I obfuscate JavaScript?
Is there a way to protect JS file from being opened and copied. Perhaps it can be encoded? Just curious.
You can minify and obfuscate it but you cannot prevent it from being downloaded. There are many tools out there allowing you to achieve this. Some popular are the Google Closure Compiler and YUI Compressor.
Obfuscating the Javascript code is your best bet if your goal is to prevent other users from stealing your javascript code. Although personally I think that is a waste of time.
Note that even obfuscated code can, to some extent, be de-obfuscated, and with enough time can be easily restored.
If it's your goal to hide information contained in your javascript file (passwords for example) then you are out of luck. These can be retrieved.
No. JavaScript that cannot be copied by the user, cannot be run by the browser.
If you are concerned about intellectual property issues, your best bet aside from obfuscation is to architect your application in such a way that leaves most of the IP uniqueness of your product on the server side of your application.