我有一个在 Wordpress 4.1.1 下运行的网站。这是现场直播。我试图在 Google 的 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,这是.htaccess
我在主机 (Bluehost) 上的文件:
# Use PHP54CGI as default
AddHandler fcgid54-script .php
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
RewriteRule .* - [E=W3TC_PREVIEW:_preview]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
# END W3TC Browser Cache
# START PageSpeed
<IfModule pagespeed_module>
ModPagespeed off
ModPagespeedEnableFilters rewrite_images,inline_images,recompress_images,convert_jpeg_to_progressive,recompress_jpeg,recompress_png,strip_image_meta_data,resize_images
ModPagespeedEnableFilters rewrite_javascript,rewrite_css,make_google_analytics_async,remove_comments,collapse_whitespace
ModPagespeedUseExperimentalJsMinifier on
</IfModule>
# END PageSpeed
为什么没有启用缓存?我还安装了 W3 Total Cache 插件。有什么建议吗?我做错了什么?如何缓存外部资源?那可以做到吗?如何?