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!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With