Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1105353 of Vary

  • Revision slug: Web/HTTP/Headers/Vary
  • Revision title: Vary
  • Revision id: 1105353
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment new page

Revision Content

{{HTTPSidebar}}

The Vary HTTP response header determines how to match future request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server.

Header type {{Glossary("Response header")}}
{{Glossary("Forbidden header name")}} no

Syntax

Vary: *
Vary: <header-name>, <header-name>, ...

Directives

*
Ech request for a URL is supposed to be treated as a unique and uncacheable request. A better way to indicate this is to use {{HTTPHeader("Cache-Control")}}: private, which is clearer to read and also signals that the object shouldn't be stored ever.
<header-name>
A comma-separated list of header names to take into account when deciding whether or not a cached response can be used.

Examples

Dynamic serving

When using the Vary: User-Agent header, caching servers should consider the user agent when deciding whether to serve the page from cache. For example, if you are serving different content to mobile users, it can help you to avoid that a cache may mistakenly serve a desktop version of your site to your mobile users. It can help Google and other search engines to discover the mobile version of a page, and might also tell them that no Cloaking is intended.

Vary: User-Agent

Specifications

Specification Title
{{RFC("7231", "Vary", "7.1.4")}} Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

Browser compatibility

{{Compat}}

See also

  • {{HTTPHeader("Cache-Control")}}
  • {{HTTPHeader("User-Agent")}}

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>Vary</code></strong> HTTP response header determines how to match future request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Response header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
Vary: *
Vary: &lt;header-name&gt;, &lt;header-name&gt;, ...
</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt>*</dt>
 <dd>Ech request for a URL is supposed to be treated as a unique and uncacheable request. A better way to indicate this is to use {{HTTPHeader("Cache-Control")}}<code>: private</code>, which is clearer to read and also signals that the object shouldn't be stored ever.</dd>
 <dt>&lt;header-name&gt;</dt>
 <dd>A comma-separated list of header names to take into account when deciding whether or not a cached response can be used.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3>Dynamic serving</h3>

<p>When using the <code>Vary: User-Agent</code> header,&nbsp;caching servers should consider the user agent when deciding whether to serve the page from cache. For example, if you are serving different content to mobile users, it can help you to avoid that a cache may mistakenly serve a desktop version of your site to your mobile users. It can help Google and other search engines to discover the mobile version of a page, and might also tell them that no <a href="https://en.wikipedia.org/wiki/Cloaking">Cloaking</a> is intended.</p>

<pre>
Vary: User-Agent</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7231", "Vary", "7.1.4")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data/README.md">https://github.com/mdn/browser-compat-data/README.md</a> and send us a pull request.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTTPHeader("Cache-Control")}}</li>
 <li>{{HTTPHeader("User-Agent")}}</li>
</ul>
Revert to this revision