admin管理员组文章数量:1406937
I am trying to update my cache policy by adding some directives in the .htaccess file in the root of my website. Although I updated the values for javascript files to be 1 month, when using Google PageSpeed, it still displayed the previous cache values (6 hours). Why is this?
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 14 days"
</IfModule>
I am trying to update my cache policy by adding some directives in the .htaccess file in the root of my website. Although I updated the values for javascript files to be 1 month, when using Google PageSpeed, it still displayed the previous cache values (6 hours). Why is this?
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 14 days"
</IfModule>
Share
Improve this question
asked Oct 26, 2019 at 17:09
OctaviaLoOctaviaLo
1398 bronze badges
1 Answer
Reset to default 2ExpiresByType text/x-javascript "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" ExpiresByType application/x-javascript "access plus 14 days"
In order to determine the correct mime-type to use you need to look at the Content-Type
HTTP response header from your server (using your browser). The default for JavaScript files is application/javascript
- which you've not included here at all. You only need 1 directive that matches the response from your server, not 3 or 4. (You also stated 14 days
for the last directive above?)
For example:
ExpiresActive On
ExpiresByType application/javascript "access plus 1 month"
However, you also appear to be using an external host (CDN?) to serve some of your JS resources - these will obviously not be influenced by the directives on your application server. I also notice that the final response is coming from an Nginx server (possibly a proxy) - this might also be controlling the cache headers.
The <IfModule mod_expires.c>
wrapper is not required unless you intend to port your code to multiple servers where mod_expires is not installed and it is OK for these directives to fail.
when using Google PageSpeed, it still displayed the previous cache values (6 hours)
You should be manually checking the HTTP response headers Cache-Control
(and Expires
) in the browser to determine whether your directives are working or not.
本文标签: htaccessCache policy not updated according to PageSpeed
版权声明:本文标题:htaccess - Cache policy not updated according to PageSpeed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745052471a2639732.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论