为什么浏览器不发送“If-None-Match”头? [英] Why browser does not send "If-None-Match" header?

查看:1445
本文介绍了为什么浏览器不发送“If-None-Match”头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下载(并希望缓存)PHP中动态加载的图像。以下是发送和接收的标题:



请求:

  GET /url:resource/Pomegranate/resources/images/logo.png HTTP / 1.1 
主机:pome.local
连接:keep-alive
缓存控制:max-age = 0
接受:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8
User-Agent:Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 537.22( KHTML,如Gecko)Ubuntu Chromium / 25.0.1364.160 Chrome / 25.0.1364.160 Safari / 537.22
接受编码:gzip,deflate,sdch
接受语言:en-US,en; q = 0.8
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.3
Cookie:PHPSESSID = fb8ghv9ti6v5s3ekkmvtacr9u5

回复:

  HTTP / 1.1 200 OK 
日期:星期二,2013年4月9日11:00:36 GMT
服务器:Apache / 2.2.22(Ubuntu)
X-Powered-By:PHP / 5.3.14 ZendServer / 5.0
到期: 1981年11月19日星期四08:52:00 GMT
缓存控制:无存储,无缓存,必须重新验证,后检查= 0,预检查= 0
Pragma:no- cache
Content-Disposition:inline; filename =logo
ETag:1355829295
Last-Modified:Tue,18 Dec 2012 14:44:55 Asia / Tehran
Keep-Alive:timeout = 5,max = 98
连接:Keep-Alive
转移编码:chunked
内容类型:image / png

当我重新加载URL时,会发送和接收完全相同的标头。我的问题是我应该在回复中发送什么来查看后续请求中的 If-None-Match 标题?



<注意:我相信这些标题在不久前做得很好,即使我不能确定,但​​我认为浏览器已更改为不发送 If-None-Match 标题了(我以前看过那个标题)。我正在使用Chrome和Firefox进行测试,但都无法发送标题。

解决方案

你说缓存-Control:no-store,no-cache - 但期望缓存发生?



删除这些值(我认为 must-revalidate,post-check = 0,pre-check = 0 可以/应该保留 - 他们告诉浏览器检查服务器是否有变化。



我会坚持使用 Last-Modified (如果仅使用此标准可以检测到对资源的​​更改) - ETag 是一个更复杂的事情要处理(特别是如果你想在自己的PHP脚本中处理它),Google PageSpeed / YSlow也建议不要这样做。


I'm trying to download (and hopefully cache) a dynamically loaded image in PHP. Here are the headers sent and received:

Request:

GET /url:resource/Pomegranate/resources/images/logo.png HTTP/1.1
Host: pome.local
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.22 (KHTML, like Gecko) Ubuntu Chromium/25.0.1364.160 Chrome/25.0.1364.160 Safari/537.22
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=fb8ghv9ti6v5s3ekkmvtacr9u5

Response:

HTTP/1.1 200 OK
Date: Tue, 09 Apr 2013 11:00:36 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.14 ZendServer/5.0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Disposition: inline; filename="logo"
ETag: "1355829295"
Last-Modified: Tue, 18 Dec 2012 14:44:55 Asia/Tehran
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/png

When I reload the URL, the exact same headers are sent and received. My question is what should I send in my response to see the If-None-Match header in the consequent request?

NOTE: I believe these headers were doing just fine not long ago, even though I can not be sure but I think browsers are changed not to sent the If-None-Match header anymore (I used to see that header). I'm testing with Chrome and Firefox and both fail to send the header.

解决方案

You say Cache-Control: no-store, no-cache – but expect caching to happen?

Remove those values (I think must-revalidate, post-check=0, pre-check=0 could/should be kept – they tell the browser to check with the server if there was a change).

And I would stick with Last-Modified alone (if the changes to your resources can be detected using this criterion alone) – ETag is a more complicated thing to handle (especially if you want to deal with it in your PHP script yourself), and Google PageSpeed/YSlow advise against this one too.

这篇关于为什么浏览器不发送“If-None-Match”头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆