Cache Control
You can set expires
or cache-control
headers on individual SOS objects to customize the CDN cache TTL beyond the 7-day default.
Understanding Cache-Control max-age
The cache-control: max-age
directive behaves like a TTL for cached objects. It tells the CDN how long an object is considered fresh. During that time, the cached copy can be re-served without contacting the origin. Once expired, the cache may revalidate with the origin or re-download the resource, depending on the directives.
Using Cache-Control
Examples of cache-control settings:
1-hour TTL:
Cache-Control: public, max-age=3600
72-hour TTL:
Cache-Control: public, max-age=259200
7-day TTL:
Cache-Control: public, max-age=604800
The max-age
value specifies how long (in seconds) a response remains fresh after generation. The public
directive allows caching in shared caches like CDNs.
Using Expires
Alternatively, you can set a specific expiration date:
Expires: Wed, 21 Oct 2023 07:28:00 GMT
Best Practices
- Use longer
max-age
values for static assets that don’t change frequently - Consider using versioned URLs (e.g.,
/styles.v2.css
) for assets that may need updates - The CDN will respect these headers to determine caching behavior
For more detailed information on HTTP caching headers, see the MDN Cache-Control documentation.