Vary: Accept-Encoding header

Hi,

We all know that cloudflare compress content when it deliver to user. Sometime BR sometime GZIP. But it never send Vary: Accept-Encoding header.

Why?

I’m getting that header. What’s a URL that’s not showing that header?

sdayman,

You must be using gzip/mod_deflate at origin. My question is purely related to cloudflare. If cloudflare is compressing a content(origin is not compressing), why it is not adding vary accept-encoding.

Is there a private msg kind of thing in CF community. I would love to share the link.

Yeah, each of my sites send the Response Header Vary: Origin, Accept-Encoding.

see https://support.cloudflare.com/hc/en-us/articles/200168086-Does-Cloudflare-compress-resources- and it’s only for certain mime types https://support.cloudflare.com/hc/en-us/articles/200168396

Does Cloudflare compress resources?

Yes, Cloudflare applies gzip and brotli compression to some types of content. We also gzip items based on the browser’s useragent to help speed up page loading time.

If you’re already using gzip we will honor your gzip settings as long as you’re passing the details in a header from your web server for the files.

It can be dependent on your origin web server headers.

eva200,

As I told in 1st post that I know cloudflare compress certain MIME types. My Question is if we do not compress at our origin and only depend cloudflare to compress MIME, why cloudflare do not send vary accept-encoding.

Wouldn’t know exactly as I’ve never not setup gzip compression on origin - it’s basically must have for performance even if CF is front of it. Any reason why you’re not doing gzip compression or at least supporting it at the origin web server level ?

Cloudflare do not support brotli at origin. They only ask gzip/deflate content from origin. Now they ask for gzip content from origin and than convert it to brotli for the browser which support it. Dont you think it will take huge time?

Plus the rule should be whosoever compress should present accept encoding.

I haven’t noticed a difference when I had my origin with gzip disabled versus gzip enabled behind Cloudflare - especially as static files will be cached by default so it’s only a cache miss/bypass that hits the origin anyway. My Wordpress blog https://servermanager.guide/ is just as fast with gzip enabled on the origin as it was with gzip disabled at origin :slight_smile:

1 Like

Can you share how do u gzip at origin? if it is possible for you to share.

I use my own Centmin Mod LEMP stack’s Nginx 1.17 mainline builds. But for any Nginx server it’s outlined at https://docs.nginx.com/nginx/admin-guide/web-server/compression/

For Apache 2.4 https://httpd.apache.org/docs/2.4/mod/mod_deflate.html

Just search for guides on nginx or apache 2.4 gzip compression i.e. https://tecadmin.net/enable-gzip-compression-apache-ubuntu/

1 Like

I used this method on server. It always set accept-encoding header. But if I dont used mod_deflate at server, cloudflare never set vary, that is my question.

<IfModule mod_deflate.c>
	DeflateFilterNote ratio
	DeflateCompressionLevel 9
	DeflateMemLevel 9
	DeflateWindowSize 15

    # Compress HTML, CSS, JavaScript, Text, XML and fonts
	AddOutputFilterByType DEFLATE text/html
	AddOutputFilterByType DEFLATE text/richtext
	AddOutputFilterByType DEFLATE text/plain
	AddOutputFilterByType DEFLATE text/css
	AddOutputFilterByType DEFLATE text/x-script
	AddOutputFilterByType DEFLATE text/x-component
	AddOutputFilterByType DEFLATE text/x-java-source
	AddOutputFilterByType DEFLATE text/x-markdown
	AddOutputFilterByType DEFLATE application/javascript
	AddOutputFilterByType DEFLATE application/x-javascript
	AddOutputFilterByType DEFLATE text/javascript
	AddOutputFilterByType DEFLATE text/js
	AddOutputFilterByType DEFLATE image/x-icon
	AddOutputFilterByType DEFLATE application/x-perl
	AddOutputFilterByType DEFLATE application/x-httpd-cgi
	AddOutputFilterByType DEFLATE text/xml
	AddOutputFilterByType DEFLATE application/xml
	AddOutputFilterByType DEFLATE application/xml+rss
	AddOutputFilterByType DEFLATE application/json
	AddOutputFilterByType DEFLATE multipart/bag
	AddOutputFilterByType DEFLATE multipart/mixed
	AddOutputFilterByType DEFLATE application/xhtml+xml
	AddOutputFilterByType DEFLATE font/ttf
	AddOutputFilterByType DEFLATE font/otf
	AddOutputFilterByType DEFLATE font/x-woff
	AddOutputFilterByType DEFLATE image/svg+xml
	AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
	AddOutputFilterByType DEFLATE application/ttf
	AddOutputFilterByType DEFLATE application/x-ttf
	AddOutputFilterByType DEFLATE application/otf
	AddOutputFilterByType DEFLATE application/x-otf
	AddOutputFilterByType DEFLATE application/truetype
	AddOutputFilterByType DEFLATE application/opentype
	AddOutputFilterByType DEFLATE application/x-opentype
	AddOutputFilterByType DEFLATE application/font-woff
	AddOutputFilterByType DEFLATE application/eot
	AddOutputFilterByType DEFLATE application/font
	AddOutputFilterByType DEFLATE application/font-sfnt
	AddOutputFilterByType DEFLATE application/wasm
</IfModule>

see https://kinsta.com/knowledgebase/specify-vary-accept-encoding-header/

apache

<IfModule mod_headers.c>
  <FilesMatch ".(js|css|xml|gz|html)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

nginx

gzip_vary on;

that is why you aren’t seeing vary accept-encoding headers as your Apache server isn’t configured for it I assume.

eva2000,

I do not think you are getting my question correctly. If I setup mod_deflate at origin. My origin set vary: Accept-encoding correctly. So for accept encoding to work I have to setup mod_deflate at origin server.

Now if I DO NOT want to set mod_deflate at server. Cloudflare gets content NOT COMPRESSED. But after doing performance tweaking it send that content to user COMPRESS(gzip/brotli). But do not send Vary header why?

If anyone compress content it should send accept encoding.

Note - > one do not see to set header for vary at apache. If any one set mod_deflate correctly it is automatically added.

got an example of curl header outputs for a static file request i.e. js or css file with Cloudflare versus without Cloudflare proxied ?

curl -sI https://yourdomain.com

and

curl -sI -H 'Accept-Encoding: gzip' https://yourdomain.com

Or if curl access isn’t available, use https://tools.keycdn.com/curl

If needed just change your domain name for a dummy domain name.

If you have a web app or something else managing your headers i.e. wordpress cache/optimisation plugins, they may also be mangling your headers served.

I haven’t used Apache in years though. I know for Nginx it works.

1 Like

Thank you for solving misery of my life. That 1 thing is bothering me for years. If browser send request with accept encoding cloudflare do send vary header. If browser not requesting for gzip content it send nozip content automatically. That way it maintain more compatibility with more browsers.

Thanks a lot again.

Proper operation is that vary accept-encoding header should sent for either compressed or non-compressed requests though and generally that should be case with Cloudflare too. If not I’d open up a Cloudflare support ticket and see if it’s a bug on CF end and/or origin config issue too.

And well most browsers would be sending the gzip compressed request.

Output from curl checks above would also help CF support in the ticket you submit.

eva2000

Now I get why cloudflare do it. If browser send Accept-encoding:gzip. cloudflare will return vary header. If it doesn’t cloudflare will send uncompressed data for older browser.

It is not a bug just a compatibility reason. Thanks again.

older browsers ? which browser/version you testing with ?

I have seen many browser, especially from MEA, SEA region which do not support gzip content. (Older mobiles).

E.G. Samsung internet browser older versions.