HTTP Header Cache Time: s-maxage and max-age

11,688

The s-maxage header is intended for proxies, while max-age is intended for regular users.

A typical end user (not using a proxy) would have the file cached for a year. The same should be the case for someone using a proxy as well, since the proxy will likely send the file unmodified, i.e. including the max-age header.

But the proxy itself would only cache it for 600 seconds, so when a different user on the same proxy comes along, their browser requests the file and the proxy grabs a fresh copy from your server.

To be honest I don't think there is any real reason to set such a short expiration date for proxies when regular users get a long expiration. You ought to set them to the same (i.e. set s-maxage to the number of seconds in a year).

Share:
11,688

Related videos on Youtube

RRN
Author by

RRN

Updated on September 18, 2022

Comments

  • RRN
    RRN over 1 year

    I am setting up a CDN for my website, I found the following sample for adding to the 'httpd.conf' file, this is used to adjust the cache-time for client and CDN:

    ExpiresActive On
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css  "access plus 1 year"
    ExpiresByType text/js   "access plus 1 year"
    ExpiresByType application/x-javascript   "access plus 1 year"
    ExpiresByType application/javascript   "access plus 1 year"
    ExpiresByType application/x-shockwave-flash   "access plus 1 year"
    
    <FilesMatch "\.(gif|jpe?g|png|ico|css|js|swf)$">
    Header set Cache-Control "s-maxage=600"
    </FilesMatch>
    

    Now suppose I updated an image file, the CDN (s-maxage=600) would refresh in 600 seconds, but how about the client? Since 'max-age' is set to 1 year, if client re-visit my web, does it still send HTTP request to check for updated contents and so download the new version? How does this work actually?

    Thanks!!

  • RRN
    RRN almost 12 years
    Thanks!! As I said, s-maxage is used for CDN, if I don't set to shorter time, once I updated the contents, CDN won't get the updated contents until old contents expired. This is what I know.
  • RRN
    RRN almost 12 years
    But I am not sure about this situation: Suppose I updated an image file, the CDN (s-maxage=600) would refresh in 600 seconds, but how about the client? Since 'max-age' is set to 1 year, if client re-visit my web, does it still send HTTP request to check for updated contents and so download the new version? How does this work actually?
  • DisgruntledGoat
    DisgruntledGoat almost 12 years
    Web browsers will honor the max-age directive and ignore the s-maxage.
  • 2523fewqf23f
    2523fewqf23f almost 4 years
    So given an object with this cache info {"age": "2604", "cache-control": "public, s-maxage=2700", "last-modified": "thu, 26 mar 2020 18:32:56 gmt"}, What is the correct freshness_time calculated by the browser's cache? Is it 2700-2604=96s or 10%*(current-time - last-modified) according to the RFC w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2.4?