Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've noticed on some sites, when I go to eg. where there javascript is stored, it is forbidden.

On my website currently, if users browse to they will see all of my javascript files nicely arranged into folders. How can I prevent them from browsing this directory and still keep my javascript working correctly?

PS. I know the user downloads the javascript when they use my site and there is no way to prevent someone from reading the source but I would like to prevent what I am describing, as I see other sites have achieved this.


share|improve this question

migrated from Sep 21 '10 at 0:57

This question came from our site for professional and enthusiast programmers.

This is a webserver setting. The exact answer depends on the webserver make/version used. Please mention which one you're using. – BalusC Sep 17 '10 at 19:47
It is Linux hosting with cPanel Control. is that what you mean? – David Willis Sep 17 '10 at 19:51
Not exactly, but in ~90% of such hosts they're using Apache HTTPD. – BalusC Sep 17 '10 at 19:55

It is Linux hosting with cPanel Control. is that what you mean?

It's likely using Apache HTTPD server. Drop a .htaccess file in the JS folder with the following content:

Options -Indexes 

This will disable directory indexing.

share|improve this answer

Ok, all of those people's answers are totally good and valid.

However, there's a much, much, much simpler way of acheiving this:

  1. Create a blank text file inside the JS folder called index.html
  2. ???
  3. Profit!
share|improve this answer

This is really a question for ServerFault, but you should be able to forbid directory indexes in the /js directory. You could also block access from browsers that don't present a referrer string in your site, though that might break some browsers.

share|improve this answer

use the .htaccess sent below, =] ... and you can compress your js files to improve the performance and to ensure the "privacy" of your scripts too:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.