designwithfocus

Domains, hosting & DNS

Server Cache vs Browser Cache: Two Places a Copy Can Sit

By Design With Focus Team 7 min read
Browser window and a server rack, each holding a small copy of a page

Short answer

A browser cache is a private copy for one person, and a server cache is a shared copy in front of the origin for many people. MDN calls the first a private cache and the second a shared cache, including CDNs and reverse proxies. Cache-Control: private keeps a personalized response out of the shared cache.

Last verified against the sources listed below.

Key takeaways

  • MDN's private cache is tied to one client and is typically the browser cache.
  • A shared cache sits between the client and the origin and can serve many users.
  • MDN lists CDNs and reverse proxies as managed caches that offload the origin.
  • A service worker is also a managed cache, so managed does not always mean a server.
  • Cache-Control: private tells a shared cache not to store that response.
  • public is for responses that must be stored even when the request used Authorization.

Server cache vs browser cache is a question of where the copy sits, not of which product is “the cache.” A browser cache is private to one client. A CDN or a reverse proxy is a shared cache on the way to the origin server. MDN’s HTTP caching guide is the vocabulary this article uses.

Browser cache vs server cache comes up again below with the header that picks the place.

No hit rate appears here, because none of those pages printed one you can copy onto your site. Page speed is why the copies exist. The headers decide who may keep them.

Two caches, two audiences

A private cache stores a response for one user, and a shared cache may store it for many. MDN says a private cache is tied to a specific client, typically the browser. A shared cache sits between the client and the server.

RFC 9111 uses the same split: a private cache is dedicated to a single user, often inside the user agent, and a shared cache stores responses for more than one user, usually as part of an intermediary.

The HTTP Working Group copy of RFC 9111 matches that wording. If the response is personalized and it lands in anything other than a private cache, another user might receive it. That is the leak MDN warns about. The header, not the mere presence of a cookie, is what marks the response private.

Cache-Control, private, and public

Cache-Control is the header that tells caches who may store the response and for how long. For a page that belongs to one logged-in person, MDN says to send Cache-Control: private. RFC 9111 says the unqualified private directive means a shared cache must not store the response. A private cache may store it.

public is narrower than the word suggests. RFC 9111 says it explicitly marks the response as cacheable and permits a shared cache to reuse a response to a request that contained Authorization. MDN says you do not need public for ordinary shared caching: if max-age is present, a shared cache may store the response.

Send public only when that Authorization case is real. Sending it on a private account page works against the private rule.

MDN also notes that responses can be stored with no Cache-Control at all, under heuristic rules, and that caches should send an explicit header instead. A max-age value is a freshness lifetime in seconds. The guide’s example of 604800 seconds is one week. That is an example lifetime, not a hit rate and not a required setting.

CDNs and reverse proxies are the server-side copy

A CDN or a reverse proxy is a managed cache in front of the origin, which is the server-side copy. MDN calls managed caches the ones service developers deploy to offload the origin. Its examples are reverse proxies, CDNs, and service workers used with the Cache API.

The first two sit on the server side of the visitor. The service worker does not. Say “CDN” or “reverse proxy” when you mean the server copy, and do not treat every managed cache as a machine in a data center.

Cloudflare’s caching page describes a CDN as proxy servers that store content closer to users than the origin servers. It says Cloudflare has CDN servers in 335+ cities. A hit means the cache already had the file, and a miss means it asked the origin and can then store the reply. The page defines those words and does not give a percentage.

Browsers, on that same page, keep HTML, JavaScript, and images on the device so the next load can reuse them. That is the private, browser-side copy. Web hosting is where the origin still has to answer when both copies miss or the response is private.

Side by side

Read the server column as a CDN or reverse proxy, using MDN’s names. Do not read it as “every managed cache,” because a service worker is managed and still on the client.

Browser cache Server cache (CDN or reverse proxy)
MDN name Private cache, typically in the browser Shared cache, and a managed cache if you deployed it
Who can be served That one client Many users, if the response may be shared
Usual header Cache-Control: private for a personalized page max-age for a shared file. public only if Authorization must still allow sharing
Clearing it The browser, or Clear-Site-Data: cache A purge or expiry on that cache. Clearing the browser does not do this
Personalized HTML Allowed in the private cache Must not be stored there if you sent private

MDN says Clear-Site-Data: cache clears browser caches and does not affect intermediate caches. A force reload in the browser sends Cache-Control: no-cache on the request. That is the visitor asking for a check. It is not a purge of every CDN city.

Images are a common shared file. An image compressor makes the file smaller before either cache stores it. The compressor does not set Cache-Control. You still choose private or a shared lifetime on the response.

Which copy to use

Use the browser’s private cache for anything that changes per person. Use a CDN or reverse proxy for bytes that are the same for everyone. The decision is the header plus what you deploy, not a slogan.

  • Send Cache-Control: private on account pages, carts, and other responses that include one user’s data.
  • Send a shared lifetime, such as max-age, on files that are identical for every visitor, such as a logo or a published image.
  • Add public only when a shared cache should store a response even though the request had Authorization, which is the case RFC 9111 and MDN describe.
  • Do not expect a cookie, by itself, to keep a response out of a shared cache.
  • Purge the CDN when you replace a shared file and cannot wait for max-age. Clearing one browser will not do that job.
Need Where the copy should sit
Logged-in HTML Private browser cache only
Same image for every visitor Shared CDN or reverse proxy, and the browser may keep a copy too
Need the origin to see every request Do not store it, or require revalidation, using the directives in RFC 9111
Visitor says the page looks old They can reload or clear the browser cache. You may still need to purge the CDN

Fresh and stale, in MDN’s terms, depend on age and max-age. A fresh response can be reused, and a stale one has passed that lifetime. None of that promises a hit fraction, so measure your own traffic if you need a rate. The specs tell you who may store the copy.

Frequently asked questions

Does a cookie automatically make a response private?

No. MDN says personalized content is often tied to cookies, but a cookie by itself does not mark the response private. If the page changes per person and you only want the browser to keep it, send Cache-Control: private. RFC 9111 says the unqualified private directive means a shared cache must not store the response, while a private cache may. Skipping the header and hoping the cookie is enough leaves the rule unstated.

When should I send Cache-Control: public?

RFC 9111 says public explicitly marks a response as cacheable and permits a shared cache to reuse it for a request that included Authorization. MDN says the same effect, and adds that public is unnecessary when you only need ordinary sharing: a response can be stored in a shared cache if max-age is set. Use public when Authorization is in play and you still want sharing. Do not add it to a page that contains one user's data.

Will clearing the browser cache empty a CDN?

No. MDN says the Clear-Site-Data: cache header clears browser caches and has no effect on intermediate caches. A CDN is one of those intermediate, shared stores. Cloudflare describes a CDN as proxy servers that keep a copy closer to users than the origin. The visitor can drop their own copy and still receive the CDN's copy until that copy expires or someone purges it. Purging is a control on the CDN, not a button in the browser.

What is a cache hit if there is no percentage to expect?

Cloudflare's caching page defines a hit as a request the cache can answer because it already stored the content, and a miss as a request it must pass to the origin. It does not publish a hit rate you should assume. After a miss, the CDN can store the origin's reply so a later request can hit. MDN describes the same idea as reuse when a stored response is still fresh. The rate depends on the site and the headers, not on a fixed percent.

Are service workers a server cache?

MDN lists service workers, together with the Cache API, as one example of a managed cache, beside reverse proxies and CDNs. A service worker runs on the client. A CDN or reverse proxy is the managed cache that sits on the way to the origin server. Call the CDN the server-side copy. Call the service worker a client-side managed cache. The word managed only means someone deployed it on purpose. It does not tell you which machine holds the bytes.

Sources