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.

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

5 Answers 5

1

If you're using Apache here is some helpful documentation:

http://mail-archives.apache.org/mod_mbox/httpd-users/200607.mbox/%[email protected]%3E

http://www.thesitewizard.com/apache/prevent-directory-listing-htaccess.shtml

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!
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.

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/

You must log in to answer this question.