我这里有个问题。
我正在使用 ETag 来验证浏览器缓存。但问题是,当我执行 window.location.pathname
时,它往往会从缓存中获取页面。但是当我在页面上执行 F5 时,它会向服务器发送重新验证请求。
我想在执行 window.location.pathname
时重新验证缓存。或者有更好的方法吗?
这是我的请求和响应 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
最佳答案
像这样怎么样:window.location.pathname + '?' + (+(新日期))
?
关于javascript - 如何告诉浏览器重新验证缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766550/