0

My question is : how can you hide a javascript file even if you need to use it ?

It is possible to denied access to the source code of a javascript file ? Like if I insert it in my page, functions and other stuff will work but when someone try to access it directly or whatever, it will fail. Any ideas ?

I've done some research but didn't found what I really wanted.

6
  • 2
    short version: its impossible, long version: there are tricks to make access to file very complicated, but they will not stop a dedicated attacker Commented Jan 14, 2012 at 1:06
  • possible duplicate of How can we restrict the user from saving a web page? Commented Jan 14, 2012 at 1:06
  • 1
    If you're worried about people reviewing you code, you could obfuscate it with a tool like dean edward's packer. It won't make it impossible to decode but it would be a pain. Also, obfuscation will cause a performance hit. Commented Jan 14, 2012 at 1:09
  • JavaScript files are publicly distributed by web-servers. Commented Jan 14, 2012 at 1:12
  • 1
    Technically, if you inline all your JS code so that it's not in an external file, it can't be hotlinked by others directly via <script> tags. They'd have to scrape your page and extract the code. But nothing prevents someone from viewing the source of your page and cut/pasting the code manually. Commented Jan 14, 2012 at 1:30

4 Answers 4

3

The short answer, no it can not.

If its being executed, its being seen.

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

Comments

2

Because javascript is an interpreted language (not compiled) a copy of the source code has to be copied to the users computer. There is no way to stop them from looking at it on their hard drive or using the built in functions of their browser.

Comments

1

http://www.stunnix.com/prod/jo/

You can use this tool or similar ones to make it harder for your code to be human readable, but you can't stop people from looking at the code.

Comments

1

If you're transmitting a file to a user, they can look at it.

The only to guarantee a user can't look at the contents of a file is to not send it to them.

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.