Request headers that influenced a response should be listed in a Vary
response header.
This tells Unpoly to partition its cache for that URL so that each request header value gets a separate cache entries.
You can set a Vary
header manually from your server-side code. You may also be using
a library like unpoly-rails that sets the Vary
header automatically.
Tip
Server-side Unpoly apps may inspect request headers to customize or shorten responses, e.g. by omitting content that isn't targeted. When a response is optimized in that fasion, a
Vary
header should be sent.
The user makes a request to /sitemap
in order to updates a fragment .menu
.
Unpoly makes a request like this:
GET /sitemap HTTP/1.1
X-Up-Target: .menu
The server may choose to optimize its response by only render only the HTML for
the .menu
fragment. It responds with the HTTP seen below. Note that it includes a Vary
header
indicating that the X-Up-Target
header has influenced the response body:
Vary: X-Up-Target
<div class="menu">...</div>
After observing the Vary: X-Up-Target
header, Unpoly will partition cache entries to /sitemap
by X-Up-Target
value.
That means a request targeting .menu
is no longer a cache hit for a request targeting a different selector.
See How cache entries are matched for more examples.