图片不缓存?

发布于 2024-10-20 22:15:09 字数 774 浏览 2 评论 0原文

我确信我网站上的某些图像没有正确缓存。我已尽我所能设置标题,但每次我点击刷新按钮时,它们似乎仍然会再次下载。

例如,下载特定图像总是需要 1 秒多一点的时间。即使在应该被缓存之后也是如此。以下是响应标头:

HTTP/1.1 200 OK
Date: Sun, 06 Mar 2011 12:51:52 GMT
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.16
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: bytes
Content-Length: 19211
Cache-Control: max-age=630323456, public
Expires: Wed, 03 Mar 2021 12:51:52 GMT
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: image/png

这有什么问题吗?谢谢。

更新

<FilesMatch "\.(htm|html|php)$">
    Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"  
</FilesMatch>

I'm convinced that certain images on my site are not caching properly. I have set the headers as best I can, but it still seems like they download again every time I hit the refresh button.

For example, a particular image always takes a bit over 1 second to download. This is even after it should be cached. Here are the response headers:

HTTP/1.1 200 OK
Date: Sun, 06 Mar 2011 12:51:52 GMT
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.16
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: bytes
Content-Length: 19211
Cache-Control: max-age=630323456, public
Expires: Wed, 03 Mar 2021 12:51:52 GMT
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: image/png

Is there anything wrong with this? Thanks.

UPDATE

<FilesMatch "\.(htm|html|php)$">
    Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"  
</FilesMatch>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潜移默化 2024-10-27 22:15:09

您的 Last-Modified 为 1970 年,您的 max-age 为 630323456 秒(19 年)。因此该文件自 1989 年以来已“过期”,必须重新下载。浏览器正在做它应该做的事情。

解决方案:

  1. 将Last-Modified更改为真实Last-Modified(可能是过去几年的某个时间)

  2. 将 max-age 更改为

  3. 删除 Expires 标头;当您也有 max-age 时,它​​会被覆盖。 请参阅 RFC2616 第 14.9.3 节。或者,删除 Cache-Control 标头并仅保留 Expires 标头。两者之一都可以,但只能使用其中之一,而不是两者都使用。

Your Last-Modified says 1970, and your max-age is 630323456 seconds (19 years). So the file has been 'expired' since 1989, and must be re-downloaded. The browser is doing what it should be doing.

Solution:

  1. Change the Last-Modified to the real Last-Modified (probably some time in the past few years)

  2. Change the max-age to

  3. Remove the Expires header; it is overridden when you also have max-age. See RFC2616 section 14.9.3. Alternatively, delete the Cache-Control header and keep only the Expires header. Either one is fine, but only use one, not both of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文