【问题标题】:Wordpress not caching properlyWordpress 没有正确缓存
【发布时间】:2018-02-07 18:08:54
【问题描述】:

我正在尝试让我的 wordpress 网站缓存,但无论我做什么,它都无法正确缓存。

在运行谷歌页面洞察时,我不断得到这个结果

我已经尝试安装 wordpress 插件并修改我的 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 image/svg "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/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 ##
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf|svg)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>

每当我加载网站并检查谷歌浏览器开发者网络工具时,它都会显示

 no-cache, must-revalidate, max-age=0

我错过了什么?我需要提高页面洞察的速度,这是减慢速度的最大原因。

注意 - 我主要开发硬编码网站,我是通过 wordpress 构建网站的新手,如果我缺少某种设置来打开它,我不知道!

【问题讨论】:

    标签: php wordpress .htaccess caching


    【解决方案1】:

    您使用共享主机吗?

    您是否启用了 mod_expires?

    这是 2 个重要因素,如果您使用共享主机,请尝试询问您的提供商是否启用/安装了 mod_expires。

    您使用的是 Nginx 还是 Apache2?

    【讨论】:

    • 它托管在包含大约 200 个其他网站的服务器上,所有这些缓存都可以正常工作,没有任何问题
    • 你检查过另一个域的 .htaccess 并进行比较了吗?
    • 是的,没有大的区别。
    • 奇怪,你有激活插件吗?
    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 2017-03-12
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    相关资源
    最近更新 更多