利用浏览器缓存 - 更新无效

时间:2016-04-20 17:48:54

标签: .htaccess web

我正在使用Google页面速​​度洞察来提高性能,但无论我做什么,我都无法让'杠杆浏览器缓存'消失。

我已经修改了几个在线文章中描述的htaccess文件,并添加了我能够的所有组合。在页面洞察中,它抱怨CSS / PNG / JS / JPG文件。

# Expires Caching Start #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 2 day" 
ExpiresByType text/html "access 2 day" 
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month" 
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
ExpiresByType text/x-javascript "access plus 1 month"  
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/x-javascript "access 1 month"
</IfModule>
# Expires Caching End # 

3 个答案:

答案 0 :(得分:6)

你似乎想念你,加上&#34;访问加1个月&#34;在许多方面。 默认值应该是可读性的第二行

以下是h5bp模板的一部分:

ExpiresActive on
ExpiresDefault                                      "access plus 1 month"
ExpiresByType text/css                              "access plus 1 year"
ExpiresByType text/html                             "access plus 0 seconds"
ExpiresByType application/javascript                "access plus 1 year"
ExpiresByType application/x-javascript              "access plus 1 year"
ExpiresByType text/javascript                       "access plus 1 year"

... https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

答案 1 :(得分:4)

如果你正在使用Apache,你可能想运行这些,因为这对我有用:

sudo a2enmod headers
sudo a2enmod expires
service apache2 restart

您也可以尝试使用此代码:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

答案 2 :(得分:0)

也许试试这个:

# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>