Set HTTP Caching Expiration, Recommended by Google PageSpeed

前端 未结 2 1144
春和景丽
春和景丽 2020-12-23 14:45

I ran tests on my website using Google\'s PageSpeed and it recommends that I \"Leverage browser caching\" and provided the following resource:

http://code.google.co

2条回答
  •  [愿得一人]
    2020-12-23 15:23

    In your root's .htaccess:

    
      ExpiresActive On
      ExpiresDefault "access plus 1 seconds"
      ExpiresByType image/x-icon "access plus 2592000 seconds"
      ExpiresByType image/jpeg "access plus 2592000 seconds"
      ExpiresByType image/png "access plus 2592000 seconds"
      ExpiresByType image/gif "access plus 2592000 seconds"
      ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
      ExpiresByType text/css "access plus 604800 seconds"
      ExpiresByType text/javascript "access plus 216000 seconds"
      ExpiresByType application/x-javascript "access plus 216000 seconds"
      ExpiresByType text/html "access plus 600 seconds"
      ExpiresByType application/xhtml+xml "access plus 600 seconds"
    
    

    And follow by:

    
    
    Header set Cache-Control "max-age=2692000, public"
    
    
    Header set Cache-Control "max-age=2692000, public"
    
    
    Header set Cache-Control "max-age=216000, private"
    
    
    Header set Cache-Control "max-age=600, private, must-revalidate"
    
    Header unset ETag
    Header unset Last-Modified
    
    

    This is the exact same code I use on every property I manage and offers me (and PageSpeed) the most satisfying results. One may argue on specific rules, that's why I said that it satisfies me, but it certainly satisfies PageSpeed.

提交回复
热议问题