我问我的主机他们是否支持mod_expires,他们告诉我它被支持。我使用CakePHP,并在webroot/.htaccess
和`app_root / .htaccess中尝试了以下代码,但考虑到css,js,png,jpg等的缓存问题,Google的页面速度仍然很高。它24小时就发现了它们!如屏幕截图所示
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=31449600, public"
</FilesMatch>
上面的代码是从本文采用的。
我也使用以下内容:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 year"
ExpiresByType text/html "access 1 month"
# ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType text/javascript "access 1 year"
ExpiresByType application/javascript "access 1 year"
# ExpiresByType application/x-shockwave-flash "access 1 month"
# ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 year"
</IfModule>
我也尝试将两个代码互相使用,但是Google Speed告诉我的是相同的。查看以下屏幕截图:
我需要知道如何解决这个问题?!
编辑##
我注意到在Firefox中使用firebug时,我注意到,
app/views/themed/slate/webroot
上面提到的缓存设置不会影响中的资源,但是直接在中找到的资源app/webroot
(即没有主题化设置)会受到很大影响。
似乎是cakephp中的错误。在CakePHP 1.3+的主题视图资产已经从移动app/webroot/themed/themeTitle
到app/views/themed/themeTitle/webroot
。
根据CakePHP 1.3文档,通过创建以下主题,您可以还原主题静态资产的旧位置(即主webroot中)app/webroot/theme/themeTitle
链接到静态资产与1.2略有不同。您仍然可以使用现有的app / webroot / themed并直接链接到这些静态文件。请注意,您将需要使用完整路径来链接到app / webroot / themed中的资产。如果要将主题资产保留在app / webroot中,建议将app / webroot / themed重命名为app / webroot / theme。这将使您能够利用核心帮助程序路径查找。以及保留不通过PHP提供资产的性能优势。
因此,我为解决此问题所做的就是将所有文件复制app/views/themed/slate/webroot
到app/webroot/theme/slate
以下屏幕截图来自FireFox Firebug,它显示图像文件在一年后以秒为单位到期:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句