How to speed up web development with correct Apach

2019-08-08 12:44发布

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.

enter image description here

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>

2条回答
叛逆
2楼-- · 2019-08-08 12:45

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.

查看更多
倾城 Initia
3楼-- · 2019-08-08 12:48

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.

查看更多
登录 后发表回答