htaccess caching not working

前端 未结 1 677
长情又很酷
长情又很酷 2020-12-29 11:53

I inputted the following into my \".htacces\" file in order to start caching the Web Content. According to Google Page Speed and Yslow the pages are still not Cached. Are th

相关标签:
1条回答
  • 2020-12-29 12:35

    Go into httpd.conf and look for the mod_expires line, it should not be commented out. Look for the mod_headers line and make sure it is not commented out.

    Or (not for a critical app) there is an easy and dirty test: remove <ifModule mod_expires.c> and </ifModule> leave stuff in between, same goes for <ifModule mod_headers.c> and if your server fails with 500 internet Server Error then your probably missing one or both of those modules and they are not enabled. If so then go into httpd.conf and enable what you need.

    You can also test your site's response headers using a tool like REDbot. Simply pick a resource URL like one pointing to an image and paste it in the tool to see what headers get sent back along with some recommendations. Note that it follows the domain's robots.txt rules and will not check the resource if it is disallowed.

    And like Gerben said, using the net tab in firefox, chrome dev tools, or some equivalent web developer tool helps see what headers are being sent and received.

    You also don't need to set Cache-Control public. And you don't need to use max age if you're also using ExpiresByType calls.

    For more info read this great tutorial: http://www.mnot.net/cache_docs/

    And learn by example: checkout how it is done in the html5-boilerplate at https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

    For other popular server config examples like lighthttpd, Node.js, Nginx, etc. see: https://github.com/h5bp/server-configs

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题