Try it on your own data
Every report in this article is in the free plan. One snippet for web and apps, up to 10 sites.
Start freeThe Expires header gives the GMT date after which a cached response is stale. Cache-Control: max-age says the same in seconds and wins when both are present, so set max-age and keep Expires as a fallback. Below: the precedence order, values by file type, nginx and Apache setup, and a curl check.
What you will learn
- Caches compute freshness from s-maxage, then max-age, then Expires minus Date, and only then guess; an invalid Expires such as 0 means already stale
- Versioned files get Cache-Control: public, max-age=31536000, immutable; HTML and fixed-URL files get no-cache plus an ETag
- Verify with curl -sI, then send the ETag back with If-None-Match and expect a 304
What the Expires header does
The Expires response header gives the date and time after which a cached copy of the response counts as stale. Until that moment a browser or shared cache may reuse the stored response without asking your server. The value is an HTTP date in GMT, for example Expires: Thu, 31 Dec 2026 23:59:59 GMT.
Two things make it less useful than it looks. First, it is an absolute clock time, so it depends on the server clock and on the Date header the same response carries; the cache works out the freshness lifetime as Expires minus Date. Second, Cache-Control: max-age expresses the same idea as a number of seconds and wins when both are present. For new work, set Cache-Control and treat Expires as the older fallback that some tools and scoring checks still look for.
What a cache does with a stale response is not "throw it away". It sends a conditional request using the validators ETag or Last-Modified, and if the file has not changed the server answers 304 Not Modified with no body. That is why the best configuration pairs a long lifetime for files that never change with a short or zero lifetime plus validators for files that do.
Expires or Cache-Control: which one wins
RFC 9111, section 4.2.1, gives the order a cache must follow when working out how long a response stays fresh: s-maxage (shared caches only) first, then max-age, then Expires minus Date. Only when none of those exists may a cache guess; the RFC says a typical guess is 10% of the time since Last-Modified. And section 5.3 says an invalid Expires date, in particular the value 0, must be treated as a time in the past, that is, already stale.
The five cases below are computed with the small script further down. All use Date: Fri, 20 Nov 2026 12:00:00 GMT.
| Case | Headers present | Freshness lifetime | Why |
|---|---|---|---|
| A | Cache-Control: public, max-age=31536000, immutable | 31,536,000 s (365 days) | max-age is used |
| B | Expires: Thu, 31 Dec 2026 23:59:59 GMT only | 3,585,599 s (41.5 days) | Expires minus Date |
| C | max-age=3600 and Expires one year ahead | 3,600 s (1 hour) | max-age beats Expires |
| D | Last-Modified: Thu, 20 Aug 2026 12:00:00 GMT only | 794,880 s (9.2 days) | Heuristic, 10% of the 92 days since modification |
| E | Expires: 0 | 0 s | Invalid date means already stale |
Case D is the one to avoid: a response with no explicit freshness information may still be cached by browsers, for a time you did not choose. Case C is the common accident when a server adds a far-future Expires by default and a framework adds a short max-age: the short one wins, silently.
What to set for each kind of file
The rule that covers most sites: files whose name changes when their content changes can be cached for a year; files whose name stays the same must be revalidated.
| File type | Example header | Reasoning |
|---|---|---|
| HTML pages | Cache-Control: no-cache plus ETag (or max-age=0, must-revalidate) | Links to the other files live here, so it must always be current; revalidation costs one small 304 |
JS and CSS with a hash or version in the URL (app.4f3a9c.js, site.css?v=a61c33dafb) | Cache-Control: public, max-age=31536000, immutable | A new build produces a new URL, so the old URL never changes |
JS and CSS with a fixed URL (/js/app.js) | Cache-Control: no-cache plus ETag, or a short max-age such as 3600 | Changes would not reach visitors for the whole lifetime otherwise |
| Images that never change | max-age=31536000, immutable if versioned; otherwise a day to a month | Large and the biggest saving |
| Web fonts | max-age=31536000, immutable | Rarely change, so one year is safe |
| API responses with personal data | Cache-Control: no-store | no-store forbids storing at all, including by CDNs |
Google's web.dev guide matches this: for versioned URLs, add Cache-Control: max-age=31536000, the longest value the specification supports; for unversioned URLs use no-cache, which lets the browser keep a copy but requires revalidation every time, and reserve no-store for responses that must never be stored. It also recommends ETag as the more accurate validator. Chrome's Lighthouse audit "Serve static assets with an efficient cache policy" flags fonts, images, media, scripts and stylesheets with a 200, 203 or 206 status and no explicit no-cache policy, and tells you to put a hash in file names so each version is unique.
| File type | Cache-Control to send | Lifetime |
|---|---|---|
| HTML pages | no-cache plus ETag | Revalidate each use |
| JS and CSS with a hash or version in the URL | public, max-age=31536000, immutable | 1 year |
| JS and CSS at a fixed URL | no-cache plus ETag, or max-age=3600 | 0 to 1 hour |
| Versioned images and fonts | public, max-age=31536000, immutable | 1 year |
| API responses with personal data | no-store | Never stored |
A starting point for most sites. Version the file name first, then lengthen the lifetime.
How much a correct cache saves
Sample data: a page weighs 520 KB: 20 KB HTML, 180 KB JavaScript, 60 KB CSS, 20 KB font and 240 KB images. A visitor views 5 pages in a session. Each page has its own HTML and images; JavaScript, CSS and the font are shared.
- No cache headers at all, and no heuristic caching: 5 × 520 KB = 2,600 KB.
- Versioned shared files cached for a year: the first page costs 520 KB; each of the next four costs only HTML and images, 20 + 240 = 260 KB. Total 520 + 4 × 260 = 1,560 KB.
- Saving: 1 − 1,560 ÷ 2,600 = 40%, and the repeat-visit saving is larger because the next session also reuses the 260 KB of shared files.
The size of the effect depends on how much of a page is shared. A site with a heavy JavaScript bundle shared across pages gains most; a page full of unique photographs gains least. Measure your own split rather than assuming.
Data transferred over 5 page views
sample data, KBHow to set the header
nginx: the expires directive sets both headers. expires 24h; produces Expires now plus 24 hours and Cache-Control: max-age=86400; a negative value gives Cache-Control: no-cache; expires max; sets a date in 2037 and a ten-year max-age. Because you usually want immutable too, set the header yourself. expires 1y; alone gives max-age without immutable, and combining it with add_header Cache-Control sends a second Cache-Control line, so use add_header only:
location ~* \.(?:js|css|woff2)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
}
Apache: enable mod_expires, then use ExpiresActive On and ExpiresByType, for example ExpiresByType image/png "access plus 1 years". The module generates both Expires and Cache-Control: max-age. If a response already has an Expires or Cache-Control header, the module leaves it alone. To add immutable, use mod_headers with the Header directive.
CDNs and hosting platforms: most let you set the browser lifetime separately from the CDN's own lifetime. Use s-maxage for the CDN and max-age for the browser if you need them to differ. And keep the header on the origin too, so you do not depend on one provider's defaults.
How to check the headers with curl
Request only the headers, then look at three lines:
curl -sI https://example.com/assets/app.4f3a9c.js | grep -iE "^(cache-control|expires|etag|last-modified|date|age)"
A real response from tapcub.com on 20 November 2026 shows the pattern for a versioned stylesheet (/assets/css/site.css?v=...):
cache-control: public, max-age=31536000, immutable
etag: "74901612811fa444ef18ec9e3626f698"
and for the HTML home page:
cache-control: public, max-age=0, must-revalidate
Then test revalidation by sending the validator back:
curl -sI -H 'If-None-Match: "74901612811fa444ef18ec9e3626f698"' https://example.com/assets/app.4f3a9c.js
An unchanged file answers 304 Not Modified. A 200 means the server ignores If-None-Match, so every stale visit re-downloads the whole file. In the browser, the Network panel's Size column reads "(disk cache)" or "(memory cache)" for a fresh hit and shows a small transfer for a 304.
To compute the freshness lifetime from a header set, as in the table above:
import re
from email.utils import parsedate_to_datetime as pd
def lifetime(h):
h = {k.lower(): v for k, v in h.items()}
m = re.search(r'max-age=(\d+)', h.get('cache-control', ''))
if m: return int(m.group(1))
if 'expires' in h:
try: return max(0, int((pd(h['expires']) - pd(h['date'])).total_seconds()))
except Exception: return 0 # invalid date: already stale
if 'last-modified' in h:
return int(0.1 * (pd(h['date']) - pd(h['last-modified'])).total_seconds())
return 0
Common mistakes
- A far-future lifetime on a file whose URL never changes. Visitors keep the old CSS for a year after you fix it. Fix: add a hash or version to the URL, or switch the file to
no-cache. - A long
max-ageon HTML. The page keeps pointing to old file names. Useno-cacheormax-age=0, must-revalidatefor HTML. - Confusing
no-cacheandno-store.no-cachemeans "store it, but check before using it";no-storemeans "do not store it". Usingno-storeon static files throws away the whole benefit. - Two conflicting headers.
max-age=3600next to anExpiresa year ahead behaves as one hour (case C above). Check the final response from the server your visitors reach, not the config file. - No validators. A stale response with neither
ETagnorLast-Modifiedcannot be revalidated, so every expiry costs a full download. - Caching responses with cookies or personal data on a shared cache. Use
privateorno-store.
How to see whether caching helped in TapCub
TapCub does not set your headers and is not a CDN; it measures what real visitors experience after you change them.
- Take a baseline. Open Monitoring › Performance, which shows real-user Core Web Vitals. Note the P75 largest contentful paint and the share rated good (2.5 seconds or less) for your slowest pages, using the Slowest pages list.
- Mark the change. Add a date annotation under Configuration › Annotations on the day you deploy the cache headers so the chart shows when it happened.
- Read load timing. The report splits a load into backend (time to first byte), network transfer and frontend render. Caching static files mainly shrinks network transfer for repeat visitors; if the time to first byte is the slow part, headers will not fix it.
- Compare after a week. Return to the same pages and the same P75. Percentiles jump when a page has few samples, so judge pages with enough traffic. If the number did not move, check with curl that the headers reached visitors.
Background on speed and rankings is in how to optimize website performance, and on image weight in optimize images for the web.
FAQ
What is the Expires header?
It is an HTTP response header with a date and time, in GMT, after which the cached response is stale. Until then a browser or shared cache may reuse it without contacting the server. If the response also has Cache-Control: max-age, that takes precedence and Expires is ignored.
Should I use Expires or Cache-Control?
Use Cache-Control: max-age for new work, because it is a relative number of seconds and takes precedence. Keep Expires only if an older tool or audit still checks for it, and make sure both give the same lifetime. A mismatch is resolved in favour of max-age, which can surprise you.
What value should I use for the Expires header?
For files whose URL changes with their content, use a lifetime of one year: Cache-Control: max-age=31536000, immutable. For HTML and files with a fixed URL, use no-cache with an ETag so the browser revalidates. An Expires date in the past or the value 0 marks the response as already stale.
How do I add Expires headers in nginx or Apache?
In nginx, use expires 1y; inside a location for static files; it sets Expires and Cache-Control: max-age. In Apache, enable mod_expires, set ExpiresActive On and add ExpiresByType rules such as "access plus 1 years". To add immutable, set Cache-Control yourself with add_header in nginx or mod_headers in Apache.
How do I check whether the header is working?
Run curl -sI on the file URL and read cache-control, expires and etag. Then send the ETag back with If-None-Match and expect 304 Not Modified. In browser developer tools the Network panel shows "(disk cache)" for files served from cache.
Sources
- IETF, RFC 9111: HTTP Caching, section 4.2.1 (freshness lifetime order), 4.2.2 (heuristic freshness, typical 10%) and 5.3 (
Expires, invalid dates read as in the past). Checked 2026-11-20. - web.dev, Prevent unnecessary network requests with the HTTP Cache:
max-age=31536000for versioned URLs,no-cacheversusno-store,ETagrevalidation and304. Checked 2026-11-20. - Chrome for Developers, Serve static assets with an efficient cache policy: which resources the audit flags and the file-hash advice. Checked 2026-11-20.
- nginx, ngx_http_headers_module and Apache, mod_expires: the
expiresandExpiresByTypedirectives. Checked 2026-11-20.
Was this article helpful?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.
