3

How can I prevent users from Viewing my sites source and opening my JavaScript source file?

3
  • The answer may start with obfuscating. Check out this related (or duplicate?) question's answers. Commented Apr 19, 2012 at 8:30
  • 6
    You can't. Anything on the client side will always be visible to someone who wants to find it. You can however obfuscate it. Commented Apr 19, 2012 at 8:30
  • 1
    Is it a question related to copyright? Commented Apr 19, 2012 at 8:34

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.