mod_expires没有在JPEG图像上设置缓存控制头

时间:2021-04-13 03:51:15

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.

我无法弄清楚为什么在我正在处理的网站中,普通的旧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>

(ellipsis indicate superfluous ExpiresByType rule sections removed)

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

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.

我已经从我的/etc/apache2/apache2.conf文件直接到那里包含的几乎所有conf文件,并且找不到合理的解释。我也在摆弄,Pagesped和Chrome将它判死了几个小时,我仍然无能为力。

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根目录中只有一个.htaccess文件。 JPEG正在通过mime-type image / jpeg很好,但是缓存控制头文件丢失了,我无法弄清楚原因。

1 个解决方案

#1


5  

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.

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

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

#1


5  

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.

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

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