【发布时间】:2016-11-02 15:24:46
【问题描述】:
我一直在努力加快我的网站速度。
我在 Google 中进行速度测试时出现的一个问题是“利用浏览器缓存”。我已经查看了这个并在我的 htaccess 中添加了一些代码。请看下面:
## 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 text/js "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 ##
这对我的一些文件有效,但不是全部,我仍然收到一条消息,指出我的 js 和 css 文件的加载未设置为过期。有人可以帮忙吗?我做错了什么让他们不会过期?这是我来自 Google 的错误消息,即使之前的代码在 htaccess 中也是如此。
http://www.mydomain.co.uk/css/grid.css (expiration not specified)
http://www.mydomain.co.uk/js/addons.js (expiration not specified)
http://www.mydomain.co.uk/js/addons/jquery.cookiebar.js (expiration not specified)
http://www.mydomain.co.uk/js/addons/jquery.flexslider.js (expiration not specified)
http://www.mydomain.co.uk/js/base/html5shiv.js (expiration not specified)
http://www.mydomain.co.uk/js/base/modernizr.custom.js (expiration not specified)
http://www.mydomain.co.uk/js/nav.js (expiration not specified)
http://www.mydomain.co.uk/mailer/css/form-style.css (expiration not specified)
http://connect.facebook.net/en_US/sdk.js (20 minutes)
http://www.google-analytics.com/analytics.js (2 hours)
http://www.mydomain.co.uk/fonts/Effra_Std_Bd.woff (2 days)
http://www.mydomain.co.uk/fonts/Effra_Std_Lt.woff (2 days)
http://www.mydomain.co.uk/fonts/Effra_Std_Md.woff (2 days)
http://www.mydomain.co.uk/fonts/Effra_Std_Rg.woff (2 days)
http://www.mydomain.co.uk/mailer/js/jquery.validate.js (2 days)
http://www.mydomain.co.uk/mailer/js/validate.js (2 days)
【问题讨论】:
标签: javascript html css .htaccess caching