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

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

问题描述

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

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

请求:

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

回复:

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

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

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?

注意:我相信这些标头不久前还不错,尽管我不能确定,但​​我认为浏览器已更改为不再发送 If-None-Match 标头(我曾经看到那个标题).我正在使用 Chrome 和 Firefox 进行测试,但都无法发送标头.

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.

推荐答案

您的响应标头包括 Cache-Control: no-store, no-cache;这些会阻止缓存.

Your response headers include Cache-Control: no-store, no-cache; these prevent caching.

删除这些值(我认为 must-revalidate, post-check=0, pre-check=0 可以/应该保留 - 它们告诉浏览器检查服务器是否存在改变).

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).

而且我会坚持单独使用 Last-Modified(如果可以单独使用此标准检测到对资源的​​更改) - ETag 处理起来更复杂(特别是如果您想自己在 PHP 脚本中处理它),Google PageSpeed/YSlow 也建议不要这样做.

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天全站免登陆