1

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

On my website currently, if users browse to www.mysite.com/js 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.

Thanks.

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

5 Answers5

1

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.

1

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!
Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
0

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.

zigdon
  • 471
  • 1
  • 4
  • 8
0

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:

http://javascriptcompressor.com/

http://developer.yahoo.com/yui/compressor/