【发布时间】:2019-05-08 19:53:03
【问题描述】:
我写了一个简单的代码:
<?php
echo "<h1>1233422</h1>";
?>
<html>
<img src="screen.png"/>
</html>
html中有一张图片,但是当我刷新浏览器页面时png图片为200。
理论上图片响应状态应该是304,为什么是200?
两次请求的响应头是:
HTTP/1.1 200 OK
Content-Type: image/png
server: PhpStorm 10.0.1
date: Fri, 07 Dec 2018 03:35:42 GMT
cache-control: private, must-revalidate
last-modified: Fri, 07 Dec 2018 03:34:56 GMT
content-length: 11437
第二个请求Headers:
GET /test03-hante/screen.png HTTP/1.1
Host: localhost:63342
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
Accept: image/webp,image/apng,image/*,*/*;q=0.8
Referer: http://localhost:63342/test03-hante/index.php
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cookie: wp-settings-time-1=1539853185; Webstorm-b87204fd=531be1b1-a109-47c6-97d9-4dd7b886ebde
你看,没有If-Modified-Since 和If-Non-Match 参数,为什么?
【问题讨论】:
-
这是成功的代码
-
我的意思是如果有缓存,应该返回304状态以缓解服务器压力。