我正在使用CakePHP 2.6,此时我正在尝试修复Google PageSpeed警告,我坚持这个:
利用浏览器缓存 在静态资源的HTTP标头中设置到期日期或最长期限>指示浏览器从本地磁盘>而不是通过网络加载以前下载的资源。
这是我的app / webroot / .htaccess文件
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
<ifModule mod_deflate.c>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>
<files *.ctp>
SetOutputFilter DEFLATE
</files>
</ifModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 24 hours"
ExpiresByType application/javascript "access plus 24 hours"
ExpiresByType image/x-ico "access plus 24 hours"
ExpiresByType image/jpg "access plus 24 hours"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/gif "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "access plus 24 hours"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
答案 0 :(得分:0)
引用https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
我们建议静态资产或不经常更改的资产的最短缓存时间为一周,最好为一年。
因此,请尝试将到期时间从“访问加24小时”增加到“访问加1周”。