Reputation: 431
How can I prevent users from Viewing my sites source and opening my JavaScript source file?
Upvotes: 3
Views: 3698
Reputation: 13276
The user agents need to see and interpret the contents of the javascript. Hence unless your script belongs to a server side program (like node.js) you cannot prevent the user agent from accessing the script and in result the user from opening the javascript source file.
But, what you can do is to use obfuscation tools which would make your javascript code difficult to read for humans. With enough persistence even this can be reverse engineered. One example for such obfuscation tool is closure compiler.
So, you may maintain two versions. One version which is not obfuscated for debugging purposes and one for release mode. Also, note bugs in these obfuscation tools can lead to debugging night mares.
Upvotes: 5