简体   繁体   English

无法使用Wordpress和.htacces利用缓存浏览器

[英]Cant leverage cache browser using wordpress and .htacces

I have the following code in my wordpress .htacces 我的wordpress .htacces中有以下代码

    ## 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 ##

However its not working, im still having lots of caching errors in Google Pagespeed. 但是,它不起作用,即时通讯在Google Pagespeed中仍然存在很多缓存错误。

Your syntax is fine. 您的语法很好。 If it isn't working, mod_expires can't be enabled. 如果不起作用,则无法启用mod_expires。

  • Enable mod_expires: a2enmod expires 启用mod_expires: a2enmod expires
  • Restart Apache: /etc/init.d/apache2 restart 重新启动Apache: /etc/init.d/apache2 restart

Try this: 尝试这个:

# Enable browser caching for most static assets, 1 month
<filesMatch ".(css|jpg|jpeg|png|gif|pdf|js|ico|svg|ttf|woff|woff2)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

Change the max-age to the number of seconds you want. max-age更改为所需的秒数。 Mine is set to 1 month. 我的设定为1个月。

This uses cache-control instead of expires. 这使用缓存控制而不是过期。 Cache-control is the more modern solution. 缓存控制是更现代的解决方案。 A good overview of the differences and how to use each is here: http://dev.mobify.com/blog/beginners-guide-to-http-cache-headers/ 有关差异以及如何使用它们的一个很好的概述在这里: http : //dev.mobify.com/blog/beginners-guide-to-http-cache-headers/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM