I'm not sure if anyone else actually addressed your question directly, which is viewed by code from the View Source command. [/ p>
As others have said, there is no way to protect javascript designed to work in a browser from a specific viewer. If the browser can launch it, then any specific person can view and launch it.
But, if you put your javascript in an external javascript file that is included:
<script type="text/javascript" src="http://mydomain.com/xxxx.js"></script>
then the javascript code will not be immediately visible using the "View Source" command - only the script tag will be visible this way. This does not mean that someone cannot simply download this external javascript file to see it, but you asked how to save it in the View Source browser, and that will do it.
If you want to really do more work to view the source, you will do all of the following:
- Put it in an external .js file.
- Obfuscate the file in such a way that most variable names are replaced with short versions, so that all unnecessary spaces are removed, so they cannot be read without further processing, etc.
- Dynamically include a .js file by programmatically adding script tags (e.g. Google Analytics). This will make it difficult to access the source code from the View Source command, as there will be no easy link to click there.
- Put so much interesting logic that you want to protect on the server that you retrieve through ajax calls, not local processing.
With that said, I think you should focus on performance, reliability, and a great application. If you absolutely need to protect some algorithm, put it on the server, but, in addition, compete to be the best with you, not the secrets. Ultimately, how success works on the Internet anyway.
jfriend00 Jul 29 '11 at 6:20 2011-07-29 06:20
source share