Vary HTTP response header: Principles, Types, Working Examples

The Vary HTTP response headers determine how upcoming request headers should be combined. Vary HTTP header is necessary to decide whether or not a cache response is supplied to reduce response time or a new response will be requested to the origin server. An HTTP cache is local storage used to store cacheable response messages to decrease the response time and network bandwidth consumption. A web server uses a Vary HTTP header to specify the headers used for choosing a Representation in a content negotiation algorithm. A Representation is a set of data that represents a past, present, or desired state of a specified resource, in a format that can be communicated easily, and that includes a set of representation metadata and a possibly unbounded stream of representation data. A Vary HTTP header is vital to improve efficiency by reducing the possible uncompressed files generated by a server.

What are the principles of Vary HTTP response header?

Vary HTTP response header serves a vital role to the server. Vary HTTP response header defines the format of content needed from the webserver. What is the Syntax of Vary HTTP response header HTTP Request Header?

The following syntax shown below expresses the proper arrangement on how to use a Vary HTTP response header.

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

Example usage of a Vary HTTP response header below shows that the request’s Accept-encoding and Accept-language were used by the origin server as determining factors to provide the required content as a response.

  • Vary: accept-encoding, accept-language

What are the directives of Vary HTTP response header?

The following directives define the proper ruling on how to use a Vary HTTP response header.

  • <*> A single asterisk is a unique, uncacheable request. A Vary HTTP field value with “*” indicates that everything concerning the request may play a role in selecting a response representation. 
  • <header-name> A list of header names that are separated by a comma, used to determine whether or not a cached response can be used.

The Cache kinds for the browser that are related to the Vary HTTP response header are the following.

  1. Image Cache: Image cache is applied for multiple viewed images. Repeated downloading and decoding of the same image is avoided with the image cache.
  2. Preload Cache: The Preload cache is generated after clearing cache or after a user agent visits a page for the first time. Preload cache permits the creation of cache of all pages, posts, homepages, and other categories, thereby improving future page loads. 
  3. Service Worker Cache: Service worker cache lets you create a persistent medium to keep all network requests in a completely user controllable cache. The service worker cache interface is made for service workers, it is exposed on the window and can be opened from anywhere within your scripts. A service worker cache serves as a proxy between the network and web application.
  4. HTTP Cache: HTTP cache simply functions as a back/forward navigation, saving and viewing as a source with no need to return to the web server. HTTP cache contains all information the user agent downloads via HTTP. HTTP cache stores all data in response to the user agent’s requests for use in further response to future requests.
  5. HTTP/2 Push Cache: The HTTP/2 push cache is a type of cache that the browser checks if nothing before it provides a response. The HTTP/2 push cache stays with a certain connection and saves pushed objects from the server even with no requests from previous pages, but these are removed once the connection is lost.

Examples of Vary HTTP response header Use

An example of Vary HTTP response header usage shown below specifies that the request’s Accept-encoding and Accept-language fields were used as a reference by the origin server as a response while selecting the content.

  • Vary: accept-encoding, accept-language

What is the relation between Vary HTTP response header and Accept-Language?

The relation of the Vary HTTP response header and the Accept-Language is their function to provide the requested content from the webserver. Accept-Language is used by a Vary HTTP response header as a reference to provide accurate language based on the user agent’s preferences.

Koray Tuğberk GÜBÜR

Leave a Comment

Vary HTTP response header: Principles, Types, Working Examples

by Koray Tuğberk GÜBÜR time to read: 3 min
0