【问题标题】:Why refresh browser the image Response Status is 200, not 304?为什么刷新浏览器图像响应状态是200,而不是304?
【发布时间】: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-SinceIf-Non-Match 参数,为什么?

【问题讨论】:

  • 这是成功的代码
  • 我的意思是如果有缓存,应该返回304状态以缓解服务器压力。

标签: html http phpstorm


【解决方案1】:

在浏览器刷新中,HTTP 图像响应状态为“200(缓存)”,因为在刷新时从浏览器缓存中加载了图像。

您可以从这个答案中了解更多信息:https://stackoverflow.com/a/1665097/6678086

【讨论】:

  • phpStorm 网络服务器应该返回 304 然后客户端(浏览器)加载浏览器缓存。
  • @26334_zeal 根据屏幕截图,没有向服务器发出该图像的请求 - 请参阅“大小”列中的“来自内存”。在任何情况下:PhpStorm 内置 Web 服务器是一个非常简单的东西,所以它可能响应不同。但到目前为止,这对我来说看起来很正常。
猜你喜欢
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-07-05
  • 2010-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多