简体   繁体   English

CakePHP Google PageSpeed Insights利用浏览器缓存

[英]CakePHP Google PageSpeed Insights Leverage browser caching

I'm using CakePHP 2.6 and at this moment i'm trying to fix Google PageSpeed warnings, i'm stuck on this one: 我使用的是CakePHP 2.6,此刻我正试图修复Google PageSpeed警告,但我坚持使用以下警告:

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. 利用浏览器缓存在静态资源的HTTP标头中设置到期日期或最长期限>指示浏览器从本地磁盘加载先前下载的资源>而不是通过网络加载。

This is my app/webroot/.htaccess file at the moment 这是我目前的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>

Quoting https://developers.google.com/speed/docs/insights/LeverageBrowserCaching 引用https://developers.google.com/speed/docs/insights/LeverageBrowserCaching

We recommend a minimum cache time of one week and preferably up to one year for static assets, or assets that change infrequently. 对于静态资产或不经常更改的资产,我们建议最短缓存时间为一周,最好为一年。

So try increasing the expiry time from "access plus 24 hours" to "access plus 1 week". 因此,请尝试将到期时间从“访问加24小时”增加到“访问加1周”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM