利用浏览器缓存无法正常工作

时间:2016-08-28 09:36:57

标签: wordpress .htaccess seo

我正在建立一个新网站,我正在努力提高其速度和网页排名。我遇到的一个问题是利用浏览器缓存。我在网上看到了不同的解决方案,但它们似乎都不适合我。我编辑了.htaccess文件并添加了以下代码:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

我仍然无法解决错误。此外,Gtmetrix报告显示问题仅出在我的头版图像上。 (我正在使用wordpress和首页是一个静态页面)。 有没有办法按位置向特定文件添加到期标头? 在此先感谢:)

2 个答案:

答案 0 :(得分:0)

该代码仅适用于apache服务。 请在您的网站地址之间。 欲获得更多信息: https://gtmetrix.com/leverage-browser-caching.html https://developers.google.com/speed/docs/insights/LeverageBrowserCaching

答案 1 :(得分:0)

我刚解决了。您必须启用mod_expires模块。看看我的回答: - Leverage browser caching not working - Htaccess & mod_expires Active