The fastest request is the one that never leaves the device, and the second fastest is the one answered from a server a few milliseconds away. Caching and content delivery networks are the two mechanisms that make both happen. For a gaming site, whose assets are large and change rarely, they are the highest-leverage infrastructure decisions available. This guide explains the layers, the HTTP headers that control them, and the versioning discipline that makes aggressive caching safe.

Three layers of cache

CDN architecture: users, edge points of presence and the origin Three users send requests to the nearest edge point of presence. The first request for an asset misses the edge cache and is fetched once from the origin; subsequent users at that edge get a hit. Below, the three cache layers checked in order: the browser cache on the same device with zero network, the edge cache at the nearest point of presence with a short round trip, and the origin with full server work and the longest path. User AUser BUser CEdge PoP 1cache near users A, BEdge PoP 2cache near user COriginapplication serverMISS → fetch oncethen HIT for othersTHREE CACHE LAYERS, CHECKED IN ORDERBrowser cachesame device, zero networkEdge cachenearest PoP, short tripOriginfull server work, farthest
CDN architecture. Requests stop at the nearest edge when the asset is cached there; only the first miss travels to the origin. Browser cache → edge cache → origin, each slower than the last.

Every request passes through up to three caches before reaching the server that generates the content.

  • Browser cache. Stored on the user's device. A hit costs no network at all. Governed by the Cache-Control header the response carried when it was first fetched.
  • Edge cache (CDN). A content delivery network runs servers, called points of presence or edges, in many locations. The user's request is routed to the nearest one. If the edge holds a fresh copy of the asset, it answers directly; the round trip is short because the edge is close. If not, the edge fetches from the origin once and then serves every subsequent user from its copy.
  • Origin. The application server or storage that holds the authoritative content. The slowest and farthest layer, and the one you want to reach as rarely as possible.

The CDN also terminates TLS near the user, so the expensive handshakes in the latency pipeline happen over a short distance, and it typically keeps warm connections to the origin so cache misses are cheaper than a cold fetch would be. web.dev's CDN article covers these benefits and the configuration choices in more depth.

Cache-Control

HTTP caching is specified in RFC 9111 and documented on MDN. The Cache-Control response header carries directives that every cache along the path honours:

DirectiveMeaningUse for
max-age=Nfresh for N seconds after the response was generatedeverything; the core directive
s-maxage=Nlike max-age, but only for shared caches such as CDNsHTML that the edge may hold longer than the browser
public / privatemay be stored by shared caches, or only by the browserprivate for personalised responses
immutablewill never change during its freshness lifetime; skip revalidation even on reloadhashed asset URLs
no-cachemay be stored but must be revalidated before every reuseHTML that must always be current but can be served as 304
no-storemust not be stored at allsensitive responses
stale-while-revalidate=Nmay serve a stale copy for N seconds while fetching a fresh one in the backgroundedge caching of HTML and APIs

A response with no Cache-Control is not uncached; caches apply a heuristic, commonly a fraction of the time since Last-Modified, which MDN warns is unpredictable. Set the header explicitly on every response.

Freshness and revalidation

How a cache decides to serve, revalidate or fetch Flowchart. A request for game.js checks whether a cached copy exists. If not, fetch from the next layer, which returns 200 OK with Cache-Control. If it exists and is still fresh (age under max-age), serve from cache with no network at all. If stale, revalidate with If-None-Match and the ETag; the server answers 304 Not Modified (headers only, reuse the body) or 200 OK with a new body. The immutable directive skips revalidation entirely. Request for /game.jsbrowser or CDN edgeCached copy exists?look up by URLFetch from next layer200 OK + Cache-ControlnoStill fresh?age < max-ageyesServe from cacheno network at allyesRevalidateIf-None-Match: ETagno (stale)304 Not Modifiedheaders only, reuse bodyor 200 OK with a new bodyimmutable: skip revalidation entirely
Cache decision. Exists? Fresh? Serve. Stale? Revalidate with ETag and hope for 304. Hashed, immutable asset URLs never need the revalidation step.

A cached response is fresh while its age is below max-age, and the cache serves it without contacting anyone. Once it is stale, the cache may still use it, but only after asking the origin whether it has changed. That question is a conditional request: the cache sends If-None-Match with the ETag it holds (or If-Modified-Since with the date). If the content is unchanged the origin answers 304 Not Modified with headers only, and the cache reuses its stored body. If it changed, the origin sends a full 200 with the new body. A 304 still costs a round trip, which is why static assets are better served with a long max-age and immutable, so the revalidation never happens.

Immutable assets and cache busting

Long cache lifetimes are only safe if a changed file gets a new URL, because a browser holding game.js for a year will not notice the server's new version. The solution is to put a content hash in the file name, such as game.3f9a1c2e.js, and reference the new name from the HTML whenever the content changes. The old URL stays valid for anyone with an old HTML page; the new URL is a cache miss once and then cached for a year. Google's documentation notes that Googlebot may ignore caching headers, which makes fingerprinted file names the reliable way to ensure it fetches updated assets too.

Query-string versioning (site.css?v=8d0ac4e4) is the lighter alternative and is what this site uses: the HTML references each stylesheet and script with a hash of its content, and the server sends a one-year immutable policy for those file types. It works with every browser cache; its weakness is that a few CDNs and proxies ignore query strings, so hashed file names are the more robust choice for a large deployment.

HTML itself cannot be fingerprinted, since its URL is the page's address. Give it a short freshness (minutes), or no-cache with an ETag so the browser revalidates cheaply, and let the CDN hold it for longer with s-maxage and stale-while-revalidate so most users get an edge hit.

Compression: Brotli and gzip

The client lists the encodings it understands in Accept-Encoding; the server picks one, compresses the body, and names it in Content-Encoding. Both algorithms in common use are supported by all current browsers. gzip is universal and fast. Brotli (br, RFC 7932) usually compresses text 15 to 25 percent smaller than gzip at comparable settings, with slower compression at its highest levels; the standard approach is to pre-compress static files at build time with Brotli at a high level and gzip as a fallback, and to compress dynamic HTML on the fly at a moderate level. Apply compression only to text types (HTML, CSS, JavaScript, SVG, JSON, XML); image, font and audio formats are already compressed.

Because the same URL now has several representations, the response must carry Vary: Accept-Encoding so that caches store the Brotli and gzip versions separately and never hand a Brotli body to a client that cannot decode it.

A caching policy for a gaming site

ResourceURL strategyCache-Control
HTML pagesstable URLpublic, max-age=600, s-maxage=3600, stale-while-revalidate=86400
CSS, JavaScript, game runtimecontent hash in name or querypublic, max-age=31536000, immutable
Texture atlases, audiocontent hash in namepublic, max-age=31536000, immutable
Images (page)hashed if built; otherwise stablehashed: immutable; stable: max-age=2592000
API responses (public, non-personal)stablepublic, max-age=0, s-maxage=60, stale-while-revalidate=300
Personalised or session datastableprivate, no-store

The values are a reasonable starting point rather than a rule; a site with a release every hour wants shorter HTML freshness than one that changes weekly.

Service workers

A service worker is a script the browser runs in the background with its own programmable cache. It can pre-cache a game's runtime and first-scene assets on first visit, serve them instantly on return visits even when offline, and apply policies HTTP headers cannot express, such as serving a cached atlas immediately while checking for a new one. The cost is complexity and the risk of serving stale content indefinitely if the update logic is wrong. For a gaming site it is worth considering once the HTTP caching above is in place, not instead of it.

Verifying

Open the browser's network panel and look at the Cache-Control, Content-Encoding, Vary and ETag headers on a page, a stylesheet and an atlas. Reload and confirm the hashed assets come from the memory or disk cache with no request. Check that the CDN reports a cache status header (most expose one) and that a second request for an asset from the same edge is a hit. Confirm the HTML is compressed and that the server sends a real 304 for a conditional request on a stale page. None of this requires tooling beyond the browser.

Sources

Primary documentation consulted for this guide. Thresholds and API behaviour were checked against these pages on 2026-11-02.

  1. HTTP caching — MDN Web Docs
  2. Cache-Control header — MDN Web Docs
  3. ETag header — MDN Web Docs
  4. Vary header — MDN Web Docs
  5. RFC 9111: HTTP Caching — IETF RFC Editor
  6. RFC 9110: HTTP Semantics — IETF RFC Editor
  7. Prevent unnecessary network requests with the HTTP Cache — web.dev
  8. Content delivery networks (CDNs) — web.dev
  9. Compression in HTTP — MDN Web Docs
  10. RFC 7932: Brotli Compressed Data Format — IETF RFC Editor
  11. Service Worker API — MDN Web Docs
  12. Optimize Time to First Byte — web.dev