PHP 8.5.2
Preview: compression.html Size: 11.54 KB
//usr/share/doc/varnish/html/users-guide/compression.html

<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Compression &#8212; Varnish version 7.5.0 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=e2714048" />
    
    <script src="../_static/documentation_options.js?v=8214db13"></script>
    <script src="../_static/doctools.js?v=888ff710"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Content composition with Edge Side Includes" href="esi.html" />
    <link rel="prev" title="Purging and banning" href="purging.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="esi.html" title="Content composition with Edge Side Includes"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="purging.html" title="Purging and banning"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.5.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="performance.html" accesskey="U">Varnish and Website Performance</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Compression</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="compression">
<span id="users-guide-compression"></span><h1>Compression<a class="headerlink" href="#compression" title="Link to this heading">¶</a></h1>
<p>In Varnish 3.0 we introduced native support for compression, using gzip
encoding. <em>Before</em> 3.0, Varnish would never compress objects.</p>
<p>In Varnish 4.0 compression defaults to “on”, meaning that it tries to
be smart and do the sensible thing.</p>
<p>If you don’t want Varnish tampering with the encoding you can disable
compression all together by setting the parameter <cite>http_gzip_support</cite> to
false. Please see man <a class="reference internal" href="../reference/varnishd.html#varnishd-1"><span class="std std-ref">varnishd</span></a> for details.</p>
<section id="default-behaviour">
<h2>Default behaviour<a class="headerlink" href="#default-behaviour" title="Link to this heading">¶</a></h2>
<p>The default behaviour is active when the <cite>http_gzip_support</cite> parameter
is set to “on” and neither <cite>beresp.do_gzip</cite> nor <cite>beresp.do_gunzip</cite> are
used in VCL.</p>
<p>Unless returning from <cite>vcl_recv</cite> with <cite>pipe</cite> or <cite>pass</cite>, Varnish
modifies <cite>req.http.Accept-Encoding</cite>: if the client supports gzip
<cite>req.http.Accept-Encoding</cite> is set to “gzip”, otherwise the header is
removed.</p>
<p>Unless the request is a <cite>pass</cite>, Varnish sets <cite>bereq.http.Accept-Encoding</cite>
to “gzip” before <cite>vcl_backend_fetch</cite> runs, so the header can be changed
in VCL.</p>
<p>If the server responds with gzip’ed content it will be stored in memory
in its compressed form and <cite>Accept-Encoding</cite> will be added to the
<cite>Vary</cite> header.</p>
<p>To clients supporting gzip, compressed content is delivered unmodified.</p>
<p>For clients not supporting gzip, compressed content gets decompressed
on the fly while delivering it. The <cite>Content-Encoding</cite> response header
gets removed and any <cite>Etag</cite> gets weakened (by prepending “W/”).</p>
<p>For Vary Lookups, <cite>Accept-Encoding</cite> is ignored.</p>
</section>
<section id="compressing-content-if-backends-don-t">
<h2>Compressing content if backends don’t<a class="headerlink" href="#compressing-content-if-backends-don-t" title="Link to this heading">¶</a></h2>
<p>You can tell Varnish to compress content before storing it in cache in
<cite>vcl_backend_response</cite> by setting <cite>beresp.do_gzip</cite> to “true”, like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">sub</span> <span class="n">vcl_backend_response</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">beresp</span><span class="o">.</span><span class="n">http</span><span class="o">.</span><span class="n">content</span><span class="o">-</span><span class="nb">type</span> <span class="o">~</span> <span class="s2">&quot;text&quot;</span><span class="p">)</span> <span class="p">{</span>
        <span class="nb">set</span> <span class="n">beresp</span><span class="o">.</span><span class="n">do_gzip</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>With <cite>beresp.do_gzip</cite> set to “true”, Varnish will make the following
changes to the headers of the resulting object before inserting it in
the cache:</p>
<ul class="simple">
<li><p>set <cite>obj.http.Content-Encoding</cite> to “gzip”</p></li>
<li><p>add “Accept-Encoding” to <cite>obj.http.Vary</cite>, unless already present</p></li>
<li><p>weaken any <cite>Etag</cite> (by prepending “W/”)</p></li>
</ul>
<p>Generally, Varnish doesn’t use much CPU so it might make more sense to
have Varnish spend CPU cycles compressing content than doing it in your
web- or application servers, which are more likely to be CPU-bound.</p>
<p>Please make sure that you don’t try to compress content that is
uncompressable, like JPG, GIF and MP3 files. You’ll only waste CPU cycles.</p>
</section>
<section id="uncompressing-content-before-entering-the-cache">
<h2>Uncompressing content before entering the cache<a class="headerlink" href="#uncompressing-content-before-entering-the-cache" title="Link to this heading">¶</a></h2>
<p>You can also uncompress content before storing it in cache by setting
<cite>beresp.do_gunzip</cite> to “true”. One use case for this feature is to work
around badly configured backends uselessly compressing already compressed
content like JPG images (but fixing the misbehaving backend is always
the better option).</p>
<p>With <cite>beresp.do_gunzip</cite> set to “true”, Varnish will make the following
changes to the headers of the resulting object before inserting it in
the cache:</p>
<ul class="simple">
<li><p>remove <cite>obj.http.Content-Encoding</cite></p></li>
<li><p>weaken any <cite>Etag</cite> (by prepending “W/”)</p></li>
</ul>
</section>
<section id="gzip-and-esi">
<h2>GZIP and ESI<a class="headerlink" href="#gzip-and-esi" title="Link to this heading">¶</a></h2>
<p>If you are using Edge Side Includes (ESI) you’ll be happy to note that
ESI and GZIP work together really well. Varnish will magically decompress
the content to do the ESI-processing, then recompress it for efficient
storage and delivery.</p>
</section>
<section id="turning-off-gzip-support">
<h2>Turning off gzip support<a class="headerlink" href="#turning-off-gzip-support" title="Link to this heading">¶</a></h2>
<p>When the <cite>http_gzip_support</cite> parameter is set to “off”, Varnish does
not do any of the header alterations documented above, handles <cite>Vary:
Accept-Encoding</cite> like it would for any other <cite>Vary</cite> value and ignores
<cite>beresp.do_gzip</cite> and <cite>beresp.do_gunzip</cite>.</p>
</section>
<section id="a-random-outburst">
<h2>A random outburst<a class="headerlink" href="#a-random-outburst" title="Link to this heading">¶</a></h2>
<p>Poul-Henning Kamp has written <a class="reference internal" href="../phk/gzip.html#phk-gzip"><span class="std std-ref">How GZIP, and GZIP+ESI works in Varnish</span></a> which talks a bit more
about how the implementation works.</p>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <div>
    <h3><a href="../index.html">Table of Contents</a></h3>
    <ul>
<li><a class="reference internal" href="#">Compression</a><ul>
<li><a class="reference internal" href="#default-behaviour">Default behaviour</a></li>
<li><a class="reference internal" href="#compressing-content-if-backends-don-t">Compressing content if backends don’t</a></li>
<li><a class="reference internal" href="#uncompressing-content-before-entering-the-cache">Uncompressing content before entering the cache</a></li>
<li><a class="reference internal" href="#gzip-and-esi">GZIP and ESI</a></li>
<li><a class="reference internal" href="#turning-off-gzip-support">Turning off gzip support</a></li>
<li><a class="reference internal" href="#a-random-outburst">A random outburst</a></li>
</ul>
</li>
</ul>

  </div>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="purging.html"
                          title="previous chapter">Purging and banning</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="esi.html"
                          title="next chapter">Content composition with Edge Side Includes</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/users-guide/compression.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="esi.html" title="Content composition with Edge Side Includes"
             >next</a> |</li>
        <li class="right" >
          <a href="purging.html" title="Purging and banning"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.5.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="performance.html" >Varnish and Website Performance</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Compression</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
    &#169; Copyright 2010-2014, Varnish Software AS.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
    </div>
  </body>
</html>

Directory Contents

Dirs: 0 × Files: 33

Name Size Perms Modified Actions
9.47 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
11.54 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
21.79 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
22.03 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
62.18 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
13.61 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
10.10 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
9.11 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
8.23 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
5.53 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
9.93 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
14.49 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
5.35 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
7.30 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
14.62 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
19.53 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
6.05 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
16.71 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
22.26 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
37.02 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
10.69 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
5.73 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
6.23 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
6.37 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
6.84 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
5.52 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
15.92 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
8.99 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
6.04 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
13.23 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
12.90 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
5.84 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download
8.12 KB lrw-r--r-- 2024-05-09 10:06:11
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).