我有一个网站,其中包含一些从 php 脚本发送的图像。每次发送 ETag 并检查下一个请求。这很好用。在打开的第一页上,所有文件都以 200 Ok 下载,下一页以 304 Not Modified 下载。
但我注意到,如果我重新打开页面但在重新加载时(F5),则直接从 http 服务器发送的某些文件未检查是否修改了事件。
If I open the page for the first time:
Files from web server: 200 Ok
Files from php script: 200 Ok
If I press F5:
Files from web server: 304 Not Modified
Files from php script: 304 Not Modified
If I reopen the page:
Files from web server: NO REQUEST
Files from php script: 304 Not Modified
我想要做的是让浏览器跳过检查我的文件是否被修改并显示缓存版本。所以我检查了 http 和 php 脚本发送到浏览器的响应:
来自 http 服务器的静态内容:
Accept-Ranges bytes
Connection keep-alive
Content-Length 22033
Content-Type image/png
Date Sat, 15 Mar 2014 10:42:06 GMT
Etag "523c1617-5611"
Last-Modified Fri, 20 Sep 2013 09:32:07 GMT
Server nginx
由 php 脚本提供的内容:
Connection keep-alive
Content-Type image/jpeg
Date Sat, 15 Mar 2014 10:45:16 GMT
Etag c4ca4238a0b923820dcc509a6f75849b
Server nginx
Transfer-Encoding chunked
所以区别是:
Accept-Ranges, Content-Length, Last-Modified, Transfer-Encoding
但我认为唯一能让浏览器不检查更新的是 Last-Modified。因此,如果我将 Last-Modified 添加到我的 php 脚本中 - 浏览器会跳过检查更新吗?