Reputation: 1507
I have a problem here.
I am using ETag to validate the browser cache. But the problem is that when I do window.location.pathname
it tends to get the page from the cache. But when I do a F5 on the page it send request to the server for revalidation.
I want to revalidate the cache even when I do window.location.pathname
. Or is there a better way of doing it.
Here is my Request and Response header.
Request URL:http://127.0.0.1:5555/monyog-license.html
Request Method:GET
Status Code:200 OK
Request Headers
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:SessionID=fe5b68c5c1f377a063462e59a67efb90; Username=admin; IsAdmin=1; HasServerEdit=1
Host:127.0.0.1:5555
Pragma:no-cache
Referer:http://127.0.0.1:5555/monyog-login.html
User-Agent:Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.630.0 Safari/534.16
Response Headers
Cache-Control:max-age=3600, must-revalidate
Content-Encoding:gzip
Content-Length:1401
Content-type:text/html; charset=utf-8
ETag:1331890257_3961
Expires:Tue, 19 Mar 2013 07:34:04 GMT
Last-Modified:Fri, 16 Mar 2012 09:30:57 GMT
Upvotes: 1
Views: 744
Reputation: 5403
Are you running on Apache? If so, you might want to use .htaccess to control caching. Here are some examples:
# 1 YEAR
<filesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=29030400, public"
</filesMatch>
# 1 WEEK
<filesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
# 3 HOUR
<filesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=10800"
</filesMatch>
# NEVER CACHE
<filesMatch "\.(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesMatch>
You can set any filetype(s) you want by adding it to the line. Just make sure that each filetype is separated by a | like in the examples above.
Good luck!
Best,
Cynthia
Upvotes: 1
Reputation: 108
How about something like this: window.location.pathname + '?' + (+(new Date))
?
Upvotes: 1