I want to prevent other people from using my Javascript files. I know you can block them in the htaccess file like this, but is there a bit of code you can add that basically says if this file is not being run on [domain] then don't work?
Asked
Active
Viewed 64 times
2 Answers
6
This is impossible. All Javascript code is downloaded to the browser and executed locally which means that it will be readable by anybody. If you want your code to be "secret" then Javascript is not the right tool for this.
You can obfuscate it but that still is not a guarantee that someone won't be able to make sense out of it.
Icarus
- 61,819
- 14
- 96
- 113
-
5+1. If you're that concerned with security, write a server-side process to communicate with the client code. – Chris Eberle Jan 17 '14 at 20:03
-2
It depends on the the server code/framework that you're using.
Java web apps have a server.xml and context.xml that can be used to control access via domain names. You could also do the filtering yourself on the servlet.
user3208064
- 41
- 2
-
-
Thought he was asking "How do I block access for downloading the JavaScript files." – user3208064 Jan 17 '14 at 20:20
-
If someone wants your JavaScript files, there is nothing you can do that is going to stop them from gaining access to them in some way. – Anil Natha Jan 17 '14 at 20:35
-
Yes, of course. But if you wanted to only serve the JS on certain domains, you could restrict it. In any case, I assumed the question was more nuanced. – user3208064 Jan 17 '14 at 20:37
-
I wanted to serve the JS only on certain domains. So if someone were to copy the file and run it on their own domain it shouldn't work . – coolmusic Jan 19 '14 at 15:54