У меня есть сайт, работающий под WordPress 4.1.1. это это живой сайт. Я пытаюсь получить самый высокий балл на PageSpeed Insights от Google. Одна из проблем, которую я получаю в отчете:
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. Любой совет? Что я делаю не так? Как я могу кешировать внешние ресурсы? Что можно сделать? Как?
Попробуйте добавить правила истечения на вашем .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
Для внешних ресурсов (Google, Facebook, …) вы ничего не можете сделать.
Других решений пока нет …