I have got a main javascript file(say main.js) which takes values from different functions called from other javascript files. What i want is that the main should function properly as soon as it is called by the index page or any other page or script but if the users try to watch what is inside of it, they won't be able to access what is written inside of it(or else it should return a forbidden error). Also, after searching for long i got to know that .htaccess can be used to do it so i already tried these two methods:
Method 1:
Order Allow,Deny
Deny from all
This just stops the main javascript file to be loaded at all when it is called from anywhere and it stops functioning at all. Although it blocks users from viewing it directly.
Method 2:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com.*$ [NC]
RewriteRule \.(js)$ - [F]
This actually works but still the users can access it for the 1st time when they try to. Rest every other attempt after the 1st one blocks the access to that file and shows a forbidden error untill the main site is either opened again or gets refreshed. So anyone can get to see my main.js after continuously refreshing the main site page and then accessing the code from it.
I need to know how this can be achieved properly? like the script should work fine when it is being called by any other page or script but no user can actually see what is inside of it. Also, i don't know much about htaccess so a much explained version would be highly appreciated.