Php 共享主机中Wordpress站点的浏览器缓存

Php 共享主机中Wordpress站点的浏览器缓存,php,wordpress,.htaccess,caching,w3-total-cache,Php,Wordpress,.htaccess,Caching,W3 Total Cache,我有一个网站在WordPress4.1.1下运行。是现场直播。我正在努力从谷歌获得PageSpeed Insights的最高分。我在报告中遇到的一个问题是: Leverage browser caching Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources fro

我有一个网站在WordPress4.1.1下运行。是现场直播。我正在努力从谷歌获得PageSpeed Insights的最高分。我在报告中遇到的一个问题是:

Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

Leverage browser caching for the following cacheable resources:

http://connect.facebook.net/es_ES/all.js?ver=4.1.1 (20 minutes)
http://platform.twitter.com/…=O1TZPrUbWI8cZSAGqTb6v5PaU&v=1&ver=4.1.1 (30 minutes)
https://apis.google.com/js/api.js (30 minutes)
https://apis.google.com/js/client:plusone.js (30 minutes)
https://oauth.googleusercontent.com/…e:rpc:shindig.random:shindig.sha1.js?c=2 (60 minutes)
http://www.google-analytics.com/analytics.js (2 hours)
http://dynamotechnology.com/…ssets/min-css/ultimate.min.css?ver=3.9.4 (24 hours)
http://dynamotechnology.com/…/min-js/ultimate-params.min.js?ver=3.9.4 (24 hours)
http://dynamotechnology.com/…e_VC_Addons/assets/slick/ajax-loader.gif (24 hours)
http://dynamotechnology.com/…plus/css/comments-specific.css?ver=4.1.1 (24 hours)
http://dynamotechnology.com/…comments-plus/css/comments.css?ver=4.1.1 (24 hours)
http://dynamotechnology.com/…s/comments-plus/js/comments.js?ver=4.1.1 (24 hours)
http://dynamotechnology.com/…s/comments-plus/js/facebook.js?ver=4.1.1 (24 hours)

.....
对于WP,这是我在主机(Bluehost)上拥有的
.htaccess
文件:

#使用PHP54CGI作为默认值
AddHandler fcgid54 script.php
#开始W3TC页缓存核心
重新启动发动机
重写基/
RewriteCond%{HTTP:Accept Encoding}gzip
重写规则。*-[E=W3TC\u ENC:\u gzip]
重写Cond%{HTTP_COOKIE}w3tc_预览[NC]
重写规则。*-[E=W3TC\u预览:\u预览]
重写cond%{REQUEST_METHOD}=邮递
RewriteCond%{QUERY_STRING}=“”
重写cond%{REQUEST_URI}\/$
重写cond%{HTTP_COOKIE}!(注释|作者| wp \-postpass | w3tc |注销| wordpress |登录| wptouch |开关|切换)[NC]
重写条件“%{DOCUMENT_ROOT}/wp content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/{index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}”-f
重写规则。*“/wp content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/{index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}”[L]
#结束W3TC页缓存核心
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
#开始W3TC浏览器缓存
标头附加变量用户代理env=!不要改变
AddOutputFilterByType DEFLATE text/css text/x-component应用程序/x-javascript应用程序/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon应用程序/json
#扩展放气
AddOutputFilter DEFLATE js css htm html xml
#结束W3TC浏览器缓存
#起始页面速度
ModPagespeed off
ModPagespeedEnableFilters重写\u图像、内嵌\u图像、重新压缩\u图像、将\u jpeg\u转换为\u渐进、重新压缩\u jpeg、重新压缩\u png、剥离\u图像\u元数据、调整\u图像大小
ModPagespeedEnableFilters重写javascript、重写css、使google分析异步、删除注释、压缩空白
ModPagespeedUseExperimentalJsMinifier打开
#结束页速度

为什么不启用缓存?我还安装了W3总缓存插件。有什么建议吗?我做错了什么?如何缓存外部资源?这可以做到吗?如何操作?

尝试在
上添加过期规则。htaccess

# BEGIN EXPIRES
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 10 days"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/plain "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES
#开始过期
过期于
ExpiresDefault“访问加10天”
ExpiresByType文本/css“访问加1周”
ExpiresByType文本/纯文本“访问加1个月”
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/png“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType应用程序/x-javascript“访问加1个月”
ExpiresByType应用程序/javascript“访问加1周”
过期按类型应用程序/x图标“访问加1年”
#期满

对于外部资源(谷歌、Facebook等),您无能为力。

非常好,这很有效,您知道压缩或缩小JS和CSS的任何规则,或者W3 Total缓存配置吗?我也在一个共享主机中
# BEGIN EXPIRES
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 10 days"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/plain "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-icon "access plus 1 year"
</IfModule>
# END EXPIRES