How to speed up web development with correct Apache caching headers setup?

会有一股神秘感。 提交于 2019-12-24 08:47:05

问题


Despite various measure ments to setup correct caching code in htaccess file, I still get this error:

Specify a cache validator: All static resources should have either a Last-Modified or ETag header. This will allow browsers to take advantage of the full benefits of caching.

Is there anything wrong with my htaccess caching settings? If you have improvements for these settings i will be very happy to hear. Thank you very much for your suggestions.

<IfModule mod_headers.c>
  Header unset Pragma
  FileETag None
  Header unset ETag
  ExpiresActive On

  ##### DYNAMIC PAGES
  <FilesMatch "\\.(ast|php|css)$">
    Header set Cache-Control "public, max-age=3600, must-revalidate"
  </FilesMatch>

  ##### STATIC FILES
  <FilesMatch "\\.(png|svg|swf|js|xml)$">
    Header set Cache-Control "public, max-age=604800, must-revalidate"
    Header unset Last-Modified
</FilesMatch>

##### ETERNAL FILES
<FilesMatch "\\.(ico|jpg|gif|ttf|eot|pdf|flv)$">
    Header set Cache-Control "public, max-age=7257600, must-revalidate"
    Header unset Last-Modified
</FilesMatch>
</IfModule>

回答1:


You are specifically unsetting the Last-Modified header. That's the cache validator section. Remove those lines that include:

Header unset Last-Modified

Also, is your css really dynamic? CSS can be huge for a lot of websites. Try to cache that just like any other static content.




回答2:


All static resources should have either a Last-Modified or ETag header. This will allow browsers to take advantage of the full benefits of caching.



来源:https://stackoverflow.com/questions/5480773/how-to-speed-up-web-development-with-correct-apache-caching-headers-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!