问题描述
尽管采取了各种措施来在 htaccess 文件中设置正确的缓存代码,但我仍然收到此错误:
Despite various measure ments to setup correct caching code in htaccess file, I still get this error:
指定缓存验证器:所有静态资源都应具有 Last-Modified 或 ETag 标头.这将允许浏览器充分利用缓存的优势.
我的 htaccess 缓存设置有什么问题吗?如果您对这些设置有改进,我会很高兴听到.非常感谢您的建议.
Is there anything wrong with my htaccess caching settings? If you have improvements for these settings i will be very happy to hear. Thank you very much for your suggestions.
<IfModule mod_headers.c>
Header unset Pragma
FileETag None
Header unset ETag
ExpiresActive On
##### DYNAMIC PAGES
<FilesMatch "\\.(ast|php|css)$">
Header set Cache-Control "public, max-age=3600, must-revalidate"
</FilesMatch>
##### STATIC FILES
<FilesMatch "\\.(png|svg|swf|js|xml)$">
Header set Cache-Control "public, max-age=604800, must-revalidate"
Header unset Last-Modified
</FilesMatch>
##### ETERNAL FILES
<FilesMatch "\\.(ico|jpg|gif|ttf|eot|pdf|flv)$">
Header set Cache-Control "public, max-age=7257600, must-revalidate"
Header unset Last-Modified
</FilesMatch>
</IfModule>
推荐答案
您特意取消了 Last-Modified 标题.那是缓存验证器部分.删除包含以下内容的行:
You are specifically unsetting the Last-Modified header. That's the cache validator section. Remove those lines that include:
Header unset Last-Modified
另外,你的css真的是动态的吗?CSS 对于许多网站来说可能是巨大的.尝试像任何其他静态内容一样缓存它.
Also, is your css really dynamic? CSS can be huge for a lot of websites. Try to cache that just like any other static content.
这篇关于如何使用正确的 Apache 缓存标头设置加速 Web 开发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!