【问题标题】:Why does browser request file, even though Apache mod_expires is enabled?为什么浏览器请求文件,即使启用了 Apache mod_expires?
【发布时间】:2011-03-24 06:10:12
【问题描述】:

我真的被所有这些缓存的东西弄糊涂了。我正在尝试设置mod_expires 以减少从我的网站到服务器的HTTP Requests 的数量。

到目前为止,我做得很好,我安装了mod_expires,并根据http://httpd.apache.org/docs/2.0/mod/mod_expires.html 上的说明编写了一个小 .conf 文件。

现在,例如,我所有的 .png, .gif, .jpeg 文件都有一个 Cache-Control 标头。我的预期结果是,浏览器在这段时间内不会执行任何GET Request(根据Cache-Control 值给出)。但确实如此,每个文件都会触发一个请求并接收HTTP 304 not Modified

这是错误的行为,不是吗?它应该从内部缓存加载这些文件。 我不明白的一件事是,浏览器发送Response header:Cache-Control: max-age=0。应该这样吗?

这里是一个完整的示例Request + Response headers,用于单个.png file

请求

Host             dev-mgg.localdomain
User-Agent     Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.8) Gecko/20100722     Firefox/3.6.8
Accept         image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language  de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding  gzip,deflate
Accept-Charset   ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive     115
Connection     keep-alive
Referer       http://dev-mgg.localdomain/css/global/icons.css?18224
Cookie         IR_SQLPwdStore=; IR_SQLUser=sysadm
If-Modified-Since   Thu, 24 Jul 2008 06:24:11 GMT
If-None-Match   "4010127-3c4-452bf1aefd8c0"
Cache-Control   max-age=0

回应

Date         Mon, 02 Aug 2010 14:00:28 GMT
Server     Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny8 with Suhosin-Patch mod_perl/2.0.4     Perl/v5.10.0
Connection   Keep-Alive
Keep-Alive   timeout=15, max=59
Etag         "4010127-3c4-452bf1aefd8c0"
Expires   Mon, 02 Aug 2010 14:04:28 GMT
Cache-Control   max-age=240

【问题讨论】:

    标签: linux apache http caching mod-expires


    【解决方案1】:

    看起来服务器发回的 Expires 标头在未来只有 4 分钟。 Web 浏览器决定是否实际发出请求的算法(基于 Expires 值)使用当前时间与到期日期的“接近度” - 所以除非到期日期仍然很长(几周,几个月, 年),您可以确定浏览器会请求该文件。

    【讨论】:

    • 感谢您的回复,我会试一试。好点。
    • 浏览器可以根据最近最常用的算法过滤缓存,但在缓存中时不考虑到期日期?你有任何来源或测试用例来支持它吗?
    猜你喜欢
    • 2018-05-05
    • 2015-06-07
    • 2017-06-25
    • 2020-09-16
    • 1970-01-01
    • 2014-11-22
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多