I want to protect my JS files using absolute path of the URL.
Please help me.
I want to protect my JS files using absolute path of the URL.
Please help me.
Cannot be done.
You can try to hide your JavaScript and CSS in obfuscated files, but since the user's browser needs to have it in order to display your page, the resourceful user can always distill it back from there.
Update: The comments complain that I lifted this answer verbatim from a forum site. I would like to contend that it was the other way around. Check the time stamps and user names.
You can try to do this with Apache mod_rewrite:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.xyzxyz123.com/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/bad.js$ [NC]
RewriteRule .*\.(js|css)$ /bad.js [NC,R]
This basically just looks for the referer, and if it's empty, or not populated with your website (which the browser should pass in the Referer: header) then it will return the /bad.js instead. Just create a /bad.js which is empty, or contains junk code, etc.
A knowledgeable person could always figure out how to tamper with their headers to pass the Referer header, so I wouldn't consider this a catch-all.
Hope this helps.