Easy htaccess method to prevent someone from directly accessing a javascript file?

Sonny Forelli

Well-known member
May 8, 2008
2,330
89
48
Liberty City
So let's say I have site.html

site.html calls sitescripts.js from the same root directory.

is there a simple way to allow sitescripts.js to be accessed by site.html (via looking at the referring url or the site's dedicated IP address?) but prevent someone who's snooping in the code from copying sitescripts.js into:
Code:
[URL]http://domain.com/sitescripts.js[/URL]
and viewing the .js file?


Ideally actually could this redirect them to another .js file that is super confusing so that DUMB warrior forum/digital point type copycats can't (as) easily snag landing pages and related fun javascript?

edit: php would also work fine (or even better since I don't understand apache at all).
 


just minify and pack your javascript so it turns into a gibberish filled eval function...

Minify Javascript Online / Online JavaScript Packer


thank you- do you have any feedback on using:

Code:
<?php
ob_start( 'ob_gzhandler' );
?>

at the top of .js files and then renaming to .php and calling in page via changing .js extension to .php in order to easily gzip/compress these files?

In my tests it's working fine, but wonder about compatability.