mod_expires 不在 JPEG 图像上设置缓存控制标头
我不明白为什么我正在开发的网站中的普通旧 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将
no-transform
添加到mod_headers
部分,果然,一切都按预期工作。现在我可以让额头上的墙休息一下了。I added
no-transform
to themod_headers
section and sure enough, it all works as expected. Now I can give the wall a break from my forehead.