Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Vary: Accept-Encoding Header (nginx)

Tags:

nginx

I have an nginx server and can't seem to find any information on how to send Vary: Accept-Encoding headers for CSS and JS files. Does anyone have info about this?

Thanks!

like image 452
Mitchell Avatar asked Jul 09 '11 21:07

Mitchell


People also ask

What is vary accept-Encoding header?

It is allowing the cache to serve up different cached versions of the page depending on whether or not the browser requests GZIP encoding or not. The vary header instructs the cache to store a different version of the page if there is any variation in the indicated header.

How do I add a accept-Encoding header?

To check this Accept-Encoding in action go to Inspect Element -> Network check the request header for Accept-Encoding like below, Accept-Encoding is highlighted you can see.

What is the vary header?

The Vary HTTP response header describes the parts of the request message aside from the method and URL that influenced the content of the response it occurs in. Most often, this is used to create a cache key when content negotiation is in use.


2 Answers

This is from the nginx documentation.

gzip_vary syntax: gzip_vary on|off default: gzip_vary off context: http, server, location 

Enables response header of "Vary: Accept-Encoding". Note that this header causes IE 4-6 not to cache the content due to a bug (see 2 ).

There if you just add gzip_vary on; it should do it's job.

Also make sure you have any one of the directives gzip, gzip_static, or gunzip are active.

like image 133
Atanas Markov Avatar answered Sep 18 '22 13:09

Atanas Markov


Inside the server { of the domain/subdomain that you want to set it, add

    gzip on;     gzip_min_length  1100;     gzip_buffers  4 32k;     gzip_types    text/plain application/x-javascript text/xml text/css;     gzip_vary on; 

Save the file and restart nginx.

like image 24
PJunior Avatar answered Sep 20 '22 13:09

PJunior