Vary Header

Table of Content

  • Syntax
  • Directives
  • Examples
  • Browser Compatibility
  • How to modify Vary header The Vary HTTP header is a response type header used to define the characteristics that, if they differ in subsequent requests, may produce different responses. In simpler terms, a Vary header tells the cache to serve an alternate version of a file if certain conditions are met. This allows for more dynamic serving of files that might vary based on certain aspects like language, device type, encoding, etc.

Syntax

Vary: <header-name>

Replace <header-name> with the name of header which, if changed, may give a different response.

Directives

The Vary header accepts several directives which are defined headers in HTTP responses. These headers can be User-Agent, Accept-Encoding, Accept-Language, etc. The * directive indicates that any request with any possible changes in headers should get a different response.

Examples

A few examples highlighting the use of the Vary header are:

Vary: Accept-Encoding
Vary: User-Agent, Accept-Encoding
Vary: *

Browser Compatibility

Browser Compatibility
Chrome Supported
Firefox Supported
Safari Supported
Opera Supported
Edge Supported

How to modify Vary header

ModHeader is a Chrome extension that allows you to modify and manipulate HTTP request headers. It can be used to modify the Vary header for testing and development purposes.

Here's an example of how to use it:

  1. Install and open the ModHeader extension on your Chrome browser.
  2. Click on "Add".
  3. In the "Name" input box, type in Vary.
  4. In the "Value" input box, type in the header you want the response to vary by, for example Accept-Language.
  5. Save changes.

Now all your HTTP requests will be sent with the modified Vary header. This is especially useful in testing how your server handles different requests and serves various responses based on different headers.