title: CSS is not always gzipped why?
body: <p>In my Firefox or Chrome if I check the HTTP header the result are always with Content-Encoding: gzip. But I have customers reporting that they see "transfer-encoding: chunked" instead and the request are not gzipped.</p>
  
  <p><a href="http://www.example.com/public/css/style.min.css" rel="nofollow noreferrer">http://www.example.com/public/css/style.min.css</a></p>
  
  <p>If I or the customer do a gzip compression online check it's confirmed gzip is active.</p>
  
  <p><a href="https://checkgzipcompression.com" rel="nofollow noreferrer">https://checkgzipcompression.com</a> = gzip!</p>
  
  <p>But if I use a checker like this one. <a href="http://onlinecurl.com/" rel="nofollow noreferrer">http://onlinecurl.com/</a></p>
  
  <p>I also get the transfer-encoding: chunked</p>
  
  <p>Request:</p>
  
  <pre><code>GET /style/css.css HTTP/1.1
  Host: www.example.com
  Connection: keep-alive
  Pragma: no-cache
  Cache-Control: no-cache
  User-Agent: ...
  Accept: /
  Referer: http://www.example.com/
  Accept-Encoding: gzip, deflate
  Accept-Language: ...
  Cookie: ...
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Age: 532948
  cache-control: public, max-age=604800
  Content-Type: text/css
  Date: Wed, 28 Jun 2017 12:35:07 GMT
  ETag: "5349e8d595dfd21:0"
  Last-Modified: Wed, 07 Jun 2017 13:56:17 GMT
  Server: Microsoft-IIS/7.5
  Vary: X-UA,Accept-Encoding, User-Agent
  X-Cache: HIT
  X-Cache-Hits: 6327
  X-CacheReason: Static-js-css.
  X-Powered-By: ASP.NET
  X-Served-By: ip-xxx-xxx-xxx-xx.name.xxx
  x-stale: true
  X-UA-Device: pc
  X-Varnish: 993020034 905795837
  X-Varnish-beresp-grace: 43200.000
  X-Varnish-beresp-status: 200
  X-Varnish-beresp-ttl: 604800.000
  transfer-encoding: chunked
  Connection: keep-alive
  </code></pre>
  
  <p>Why are some requests not gzipped, when it should, this is my Varnish config (the part relevant for gzip):</p>
  
  <pre><code>if (req.http.Accept-Encoding) {
      if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|flv|swf)$") {
    # No point in compressing these
       remove req.http.Accept-Encoding;
      } elsif (req.http.Accept-Encoding ~ "gzip") {
    set req.http.Accept-Encoding = "gzip";
   } elsif (req.http.Accept-Encoding ~ "deflate") {
    set req.http.Accept-Encoding = "deflate";
    } else {
     # unkown algorithm
      remove req.http.Accept-Encoding;
     }
  }
  
  # Enabling GZIP
  if (beresp.http.Content-Type ~ "(text/css|application/x-javascript|application/javascript)") {
    set beresp.do_gzip = true;
  }
  
  
  if (beresp.http.Content-Encoding ~ "gzip" ) {
    if (beresp.http.Content-Length == "0") {
      unset beresp.http.Content-Encoding;
    }
  }  
  
  set beresp.http.Vary = regsub(beresp.http.Vary, "(?i)^(.*?)X-Forwarded-URI,?(.*)$", "\1\2");
  set beresp.http.Vary = regsub(beresp.http.Vary, "(?i)^(.*?)User-Agent,?(.*)$", "\1\2");
  set beresp.http.Vary = regsub(beresp.http.Vary, "^(.*?),?$", "X-UA,\1");
  set beresp.http.Vary = regsub(beresp.http.Vary, "^(.*?),?$", "\1");
  </code></pre>
  
  <p>Any ideas, thank you.</p>