mod_expires 不在 JPEG 图像上设置缓存控制标头

发布于 2024-10-19 16:29:29 字数 1259 浏览 3 评论 0原文

我不明白为什么我正在开发的网站中的普通旧 JPEG 图像(大约十几个,每个 <10 KB)不会采用它们正在使用的缓存控制标头强制进给。我使用的 .htaccess 规则基于最新的 HTML5 Boilerplate .htaccess 文件(下面的相关部分)。奇怪的是,网站中的 PNG 数量大致相同,除了其中两个之外,缓存控制标头工作正常。

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

...

# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

...

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>

(省略号表示删除了多余的 ExpiresByType 规则部分)

我已经从我的 /etc/apache2/apache2.conf 文件直接浏览到漂亮的几乎每个conf文件都包含在其中,并且找不到合理的解释。我也摆弄过,Pagesped 和 Chrome 审核了好几个小时,但我仍然一无所知。

编辑:如下所述,该网站的网络根目录中只有一个 .htaccess 文件。 JPEG 可以通过 mime 类型 image/jpeg 正常运行,但缓存控制标头丢失,我不明白为什么。

I can't figure out why plain old JPEG images (about a dozen, < 10 KB each) in a website I'm working on won't take the cache-control headers they're being force feed. The .htaccess rules I'm using are based off the most recent HTML5 Boilerplate .htaccess file (relevant section below). What's weird is there's about the same amount of PNGs in the site and, except for two of them, the cache-control headers work perfectly.

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

...

# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

...

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>

(ellipsis indicate superfluous ExpiresByType rule sections removed)

I've gone right through from my /etc/apache2/apache2.conf file through to pretty much every conf file included from there and can find no reasonable explanation. I've also fiddled, Pagesped and Chrome audited it to death for hours, and I'm still clueless.

Edit: As mentioned below, there is only one .htaccess file in the web root for this website. The JPEGs are coming through with the mime-type image/jpeg fine but the cache-control headers are missing and I can't figure out why.

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

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

发布评论

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

评论(1

多情癖 2024-10-26 16:29:29

我将 no-transform 添加到 mod_headers 部分,果然,一切都按预期工作。现在我可以让额头上的墙休息一下了。

  <IfModule mod_headers.c>
    Header append Cache-Control "public, no-transform"
  </IfModule>

I added no-transform to the mod_headers section and sure enough, it all works as expected. Now I can give the wall a break from my forehead.

  <IfModule mod_headers.c>
    Header append Cache-Control "public, no-transform"
  </IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文