GoogleSpeed洞察力利用浏览器缓存

时间:2015-09-01 15:49:39

标签: javascript php .htaccess caching

我致力于谷歌速度洞察,它要求利用浏览器缓存

我已将代码添加到.htaccess中,如下所示

## EXPIRES CACHING ##
   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 month"
   ExpiresByType application/pdf "access 1 month"
   ExpiresByType application/javascript "access 1 month"
   ExpiresByType application/x-shockwave-flash "access 1 month"
   ExpiresByType image/x-icon "access 1 year"
   ExpiresDefault "access 2 days"
   ## EXPIRES CACHING ##

js文件没有生效,我的js文件内容类型是application / javascript,因为我通过inspectelement检查了这些。

我的代码出了什么问题?我也试过

但它不再改进,并且有效期限没有添加到文件中。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您需要在代码中添加以下标记:

<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 month"
   ExpiresByType application/pdf "access 1 month"
   ExpiresByType application/javascript "access 1 month"
   ExpiresByType application/x-shockwave-flash "access 1 month"
   ExpiresByType image/x-icon "access 1 year"
   ExpiresDefault "access 2 days"
</IfModule>

在mod_expires Apache模块标记内添加您的行。