How can I block direct access to my JavaScript files?

Viewed 16437

I use Minify to minify and cache all my script requests. I only want my users to be able to access the minified versions of the JavaScript files.

Minify lies at www.example.com/min and my scripts are at www.example.com/scripts. How can I block direct access to doc_root/scripts which is where my unminified JavaScript files lie. I'd rather not put them out of the document root but it's an option.

Please note that I'm using Zend Framework, so the actual root of my application is shifted to www.example.com/public. An htaccess file handles the rewrite.

6 Answers

This answer is little bit newer, than question (only several years, that’s nothing)

You cannot deny access to JavaScript file, because they wont’t be accessible from <script> tag.

But I found a workaround:


RewriteEngine On

RewriteRule ^.*\.js$ /invalid.html [R=301,L]

Place it in your .htaccess file in your home folder of web. (under htdocs or public_html). This will automatically redirect everyone from it. So they don’t see it.

Related