Age
Description
The Age
response header indicates the time in seconds that a resource has been cached on a proxy server or in other intermediary caches since it was generated by the origin server. This header is particularly important in caching scenarios, helping clients understand how fresh or stale a cached response might be.
When a response comes from a cache rather than directly from the origin server, the Age
header indicates how long the content has been sitting in the cache. This information can be used in conjunction with other caching headers like Cache-Control
and Expires
to make decisions about cache validation or refresh.
The Age
header is calculated by adding the time the response has been cached at each intermediary cache server in the response path.
Syntax
The syntax of the Age
header follows this structure:
<seconds>
:
A non-negative integer representing the age of the response in seconds.
Example Syntax
This example indicates that the response has been cached for 120 seconds since it was generated by the origin server.
Examples
Basic Example
A response from a cached resource:
HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 11:00:00 GMT
Content-Type: text/html
Cache-Control: max-age=3600
Age: 600
<!DOCTYPE html>
<html>
<head><title>Cached Page</title></head>
<body>This content has been cached for 10 minutes.</body>
</html>
In this example, the Age
header indicates that the content has been cached for 600 seconds (10 minutes), and the Cache-Control
header specifies that it can be cached for up to 3600 seconds (1 hour).
Fresh Cache Example
A response that was just cached:
HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 11:15:30 GMT
Content-Type: application/json
Cache-Control: public, max-age=86400
Age: 5
{"status": "success", "data": "This content was cached 5 seconds ago"}
Stale Cache Example
A response that has been cached for almost as long as its maximum age:
HTTP/1.1 200 OK
Date: Mon, 02 Jun 2025 11:30:45 GMT
Content-Type: application/json
Cache-Control: public, max-age=3600
Age: 3540
{"status": "success", "data": "This content is almost stale"}
In this example, the content has been cached for 3540 seconds, which is just 60 seconds short of its maximum age of 3600 seconds.
Summary
The Age
response header provides valuable information about the freshness of cached content by indicating how long the response has been stored in caches. This information helps clients and proxies make decisions about whether to use a cached response or request a fresh one from the origin server. When used alongside other caching headers, the Age
header contributes to an efficient caching strategy that can reduce server load and improve response times for clients.