When TTFB is high, first determine whether time went to name resolution, connection setup or waiting for the first byte after the request was prepared. Then use response headers to check whether caching behaves as intended. curl's time_* fields are cumulative timestamps from the beginning of a request, not independent stage durations. Treating them as separate durations—or treating Age: 0 as proof of a cache miss—can send triage in the wrong direction.
Split Request Timings with curl
The diagram shows request phases using curl's cumulative timing points. Subtract adjacent points to estimate a phase duration. time_starttransfer is the cumulative time from the start of the request until the first byte arrives; it is not an origin-processing measurement by itself.
Sample the same URL several times without redirects, then compare differences between cumulative fields. This command uses HTTPS. If the site redirects, identify and test the final URL first so the redirect path does not distort the comparison.
curl -sS -o /dev/null \
-w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} pre=%{time_pretransfer} first_byte=%{time_starttransfer} total=%{time_total}\n' \
"https://www.example.com/"
What you should see: curl prints six cumulative timestamps in seconds. dns is when name lookup completes; connect - dns approximates TCP setup; tls - connect approximates the TLS handshake; first_byte - pre is the wait between request preparation and receiving the first byte; and total - first_byte is response-body transfer time. If the TLS field is zero or the timestamps do not line up, check the protocol, redirects and curl version before interpreting them. See the curl --write-out manual for variable definitions.
first_byte - pre includes client-to-server request transit, edge or origin processing, and the first byte's return to the client. It is not “origin time.” If the server emits Server-Timing, compare its backend measurements with curl's end-to-end time. To compare a CDN path with a direct-origin path, test from the same authorised location with the same URL, method and headers, and only if the origin permits direct access. Treat the results as diagnostic evidence, not as a subtraction that isolates the CDN's contribution: destination IP, routing, TLS termination and cache state can all differ. The curl --write-out manual defines the timing variables.
Use the median of repeated samples and look for changes in direction rather than relying on a single minimum. If lookup or handshake differences dominate, inspect DNS, network path and connection setup. If most time occurs after connection preparation, combine cache status, Server-Timing and origin logs to distinguish edge waiting from application work.
Verify Cache Behavior from Response Headers
Capture the status and response headers, then compare them with repeated requests, the CDN's own status field and origin logs. Headers do not explain the entire request path, and cache status fields are not defined identically by every CDN.
curl -sS -D - -o /dev/null "https://www.example.com/"
What you should see: the status line and response headers. Record Cache-Control, Age, Vary, ETag or Last-Modified, then consult the current CDN documentation for its proprietary hit, miss, bypass or revalidation field. If the response redirects, inspect the headers on the final response rather than treating an intermediate response as the page result.
| Field | What it can tell you | What it cannot prove alone |
|---|---|---|
Cache-Control |
Freshness and shared-cache policy, including whether validation is required | That a CDN follows the origin header unchanged; edge rules can override or rewrite policy |
Age |
The estimated age of a response obtained from a cache | That Age: 0 means a miss; a newly stored or revalidated object can be near zero |
Vary |
Request-header dimensions that must match before a stored response is reused | That every CDN uses an identical cache key; vendors can add their own dimensions |
ETag / Last-Modified |
Validators available for conditional requests | That a 304 will occur; the client must send a conditional request and the origin must handle it |
| Vendor cache-status field | That platform's reported hit, miss, bypass or revalidation state | That field names, values or hit-ratio methods are directly comparable across vendors |
Server-Timing |
Server-side phase timings that the response chooses to expose | That the origin did no work, or that a missing field means a cache hit |
Age is a clue, not a verdict. RFC 9111 requires a cache to generate Age when a stored response satisfies a request without validation, but a fresh object's estimated age can be zero. To determine whether a response was a hit, combine the CDN's documented status field, repeated requests and origin access logs.
Choose Cache-Control and Vary Deliberately
max-age controls response freshness; s-maxage applies only to shared caches and overrides max-age there. Private caches such as browsers continue to follow the applicable private-cache directives. The directives below have different meanings:
| Directive | General meaning | Check before using |
|---|---|---|
no-cache |
Storage is allowed, but a response must be validated before reuse | Whether the origin provides and correctly handles validators such as ETag or Last-Modified |
no-store |
Tells caches not to store the request or response | Whether storage must actually be avoided; this does not mean “store and validate each time” |
private |
Restricts storage by shared caches | Whether the body is user-specific and whether CDN rules override the origin policy |
s-maxage |
Sets freshness for shared caches and requires revalidation after expiry | Whether browser and CDN freshness should differ |
must-revalidate |
Once stale, the response must be successfully validated before reuse | Whether serving stale content during an outage is acceptable |
stale-while-revalidate |
Allows a stale response during the stated window while asynchronous validation occurs | Support and actual behavior in browsers and the CDN configuration |
stale-if-error |
Allows a stale response during eligible errors | Eligible error types, time window and platform implementation |
Vary declares request headers that affect a representation and therefore its cache reuse. For example, include Accept-Encoding in variant selection only when the representation actually varies by it and the cache needs to distinguish those versions. Vary: * does not match subsequent requests and is not a normal choice for a reusable cached object. Do not remove a dimension that separates user-specific content just to raise the hit rate; first ensure that personalised responses cannot be shared with other users. The extension semantics of stale-while-revalidate and stale-if-error are defined in RFC 5861.
Two common patterns:
- Content-hashed static assets can use a longer freshness lifetime when the deployment strategy supports it. Set HTML and user-specific responses separately according to update, privacy and rollback requirements; there is no universal TTL for every site.
no-cacheallows a stored copy but requires validation before reuse;no-storesays not to store. If validators are used, verify conditional request handling and ensure validators change when the representation changes.
Check how language, device or authorisation state enters the CDN's own cache key. For related analysis, see the CDN Cache Key Strategy Guide.
Troubleshoot by Symptom
| Symptom | Check first | Next step |
|---|---|---|
Age is zero or absent |
Repeated requests, cache-status field, Date and origin logs |
Use the CDN's current documentation to determine hit or revalidation; do not rely on one field |
| A changed origin header is not visible externally | Edge-rule precedence, an old copy, inconsistent origin nodes | Capture headers at the edge and from an authorised direct-origin request; check whether the platform requires a purge |
| Different users see the same personalised content | public, shared-cache rules, cache key and authorisation state |
Stop shared caching of the response, assess exposure and verify isolation after the fix |
| Content negotiation returns the wrong representation | Vary, CDN cache key and where compression occurs |
Make the cache distinguish request dimensions that actually change the response |
| The body arrives quickly but first-byte time is high | Post-connection wait, cache status and Server-Timing |
Compare application logs with CDN status; do not attribute all end-to-end wait to the origin |
Before changing production cache policy, identify whether the response contains user data, make a reversible change and verify separation between anonymous and authenticated users. If a stale response remains after a purge, see the CDN Cache Not Updating: Triage Guide.
Limitations
curlstage differences are client-side observations. They do not automatically separate internal CDN queueing, origin-fetch network time and application processing; use server timings or logs as well.- A direct-origin comparison is affected by route, destination IP, TLS termination, cache state and request headers. Simple subtraction cannot establish how much time the CDN saved.
Age, vendor cache-status fields and hit-ratio methods differ by platform; consult each vendor's documentation before comparing them.- Shared-cache policy can expose user data. Before changing
public,private, cache keys or personalised-page rules, verify that different users receive isolated responses. - TTFB does not include response-body download, browser parsing or rendering. If visible content is still slow, inspect FCP, LCP and render-blocking assets separately; see Core Web Vitals Optimization.
FAQ
How do I troubleshoot a high curl TTFB?
Start by subtracting adjacent timestamps. time_starttransfer is cumulative from request start, while time_starttransfer - time_pretransfer observes the wait after request preparation; it still cannot separate CDN, network and origin work. Use Server-Timing or server logs for more detail, and compare the same URL from the same test location.
What does an Age: 0 measurement say about a cache hit?
It does not prove a miss. Age estimates the age of a cached response, and a newly stored or revalidated object can be near zero; an absent field is not conclusive either. Check the CDN's own status field, repeated-request behavior and origin logs, and confirm how that platform defines a hit and revalidation.
Should I use no-cache or no-store for validation?
Use no-cache when a copy may be stored but must be validated before reuse; use no-store when caches must not store the request or response. RFC 9111 defines the distinction; no-cache can reduce transfer only when validators and conditional requests work correctly. For personalised data, separately verify that shared caches are disallowed.
Should I keep Cache-Control when a CDN has a cache rule?
Yes, but the effective result depends on whether the CDN overrides, ignores or rewrites that header. Check anonymous and authenticated HTTP responses, the cache key, rule precedence and the headers actually returned. A TTL shown in a console alone does not prove that the response is safe to share.
Related Providers
- Cloudflare: when edge cache policies need to be configured and verified against the platform's response-status field.
- Fastly: when edge rules need to be checked against business-specific cache keys and response headers; confirm capabilities and pricing in the relevant account documentation and contract.
References
- curl manual:
--write-out: definitions and output format fortime_*variables. - RFC 9111: HTTP Caching: normative semantics for HTTP caching,
Age,Cache-ControlandVary. - MDN: Cache-Control: descriptions of common cache directives and browser-side use.
Community & Resources
- Environment Deployment: browse deployment triage for environments, caching and response configuration.
Original source: 16IDC Original ↗