<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>OpenResty Inc. Documentation – Response Body Compression</title><link>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/</link><description>Recent content in Response Body Compression on OpenResty Inc. Documentation</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/index.xml" rel="self" type="application/rss+xml"/><item><title>Edge: Gzip Compression</title><link>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/gzip/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/gzip/</guid><description>
&lt;p>This document explains in detail how to configure and use Gzip compression in OpenResty Edge.&lt;/p>
&lt;h2 id="configuration-hierarchy-overview">
&lt;a class="header-anchor" href="#configuration-hierarchy-overview" aria-hidden="true">#&lt;/a>
Configuration Hierarchy Overview
&lt;/h2>
&lt;p>OpenResty Edge provides Gzip compression configuration at multiple levels. Listed from highest to lowest priority:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Page rule configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Page Rules &amp;gt; Actions &amp;gt; Enable Gateway Gzip / Set Gzip Type&lt;/li>
&lt;li>&lt;strong>Global custom action configuration (referenced by an HTTP application)&lt;/strong>: Global Configuration &amp;gt; Global Custom Actions &amp;gt; Actions &amp;gt; Enable Gateway Gzip / Set Gzip Type&lt;/li>
&lt;li>&lt;strong>App settings configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Settings &amp;gt; Gzip&lt;/li>
&lt;li>&lt;strong>Global rewrite rule configuration&lt;/strong>: Global Configuration &amp;gt; Global Rewrite Rules &amp;gt; Actions &amp;gt; Enable Gateway Gzip / Set Gzip Type&lt;/li>
&lt;li>&lt;strong>Global general configuration&lt;/strong>: Global Configuration &amp;gt; General Configuration &amp;gt; Gzip Configuration (enabled by default)&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: When multiple levels are configured at the same time, the higher-priority configuration overrides the lower-priority one.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-general-configuration">
&lt;a class="header-anchor" href="#global-general-configuration" aria-hidden="true">#&lt;/a>
Global General Configuration
&lt;/h2>
&lt;p>The global general configuration is the base configuration for Gzip compression, providing the default compression parameters for the entire system.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/global-config.webp"
alt=""
loading="lazy" width="3306" height="1710"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-parameters">
&lt;a class="header-anchor" href="#configuration-parameters" aria-hidden="true">#&lt;/a>
Configuration Parameters
&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Gzip switch&lt;/strong>&lt;/td>
&lt;td>On&lt;/td>
&lt;td>Globally enable or disable Gzip compression&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Gzip buffers&lt;/strong>&lt;/td>
&lt;td>32 x 4KB&lt;/td>
&lt;td>Size of the buffers used during compression; affects memory usage&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Gzip compression level&lt;/strong>&lt;/td>
&lt;td>6&lt;/td>
&lt;td>Compression level (1-22); a higher value gives a better compression ratio but is slower&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Gzip minimum length&lt;/strong>&lt;/td>
&lt;td>1000 bytes&lt;/td>
&lt;td>Compression is applied only when the response body exceeds this threshold&lt;br/>This limit is ignored for chunked transfer (Transfer-Encoding: chunked)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Gzip compressed content types&lt;/strong>&lt;/td>
&lt;td>See the list below&lt;/td>
&lt;td>Specifies the MIME types to compress with Gzip&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="default-compression-types">
&lt;a class="header-anchor" href="#default-compression-types" aria-hidden="true">#&lt;/a>
Default Compression Types
&lt;/h3>
&lt;p>By default, the system enables Gzip compression for the following MIME types:&lt;/p>
&lt;pre>&lt;code>text/plain
&lt;/code>&lt;/pre>
&lt;blockquote>
&lt;p>&lt;strong>Tip&lt;/strong>: The &lt;code>text/html&lt;/code> type is included in the compression scope by default and does not need to be listed here again.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-rewrite-rule-configuration">
&lt;a class="header-anchor" href="#global-rewrite-rule-configuration" aria-hidden="true">#&lt;/a>
Global Rewrite Rule Configuration
&lt;/h2>
&lt;p>Global rewrite rules let you configure Gzip compression for requests that match specific conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/global-rewrite-rules.webp"
alt=""
loading="lazy" width="3334" height="1730"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="available-actions">
&lt;a class="header-anchor" href="#available-actions" aria-hidden="true">#&lt;/a>
Available Actions
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Enable Gateway Gzip&lt;/strong>: Dynamically enable or disable Gzip compression&lt;/li>
&lt;li>&lt;strong>Set Gzip Compression Type&lt;/strong>: Customize the MIME types to compress&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: The compression types set here do not include &lt;code>text/html&lt;/code> by default. If you need to compress HTML content, add it manually.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-custom-action-configuration">
&lt;a class="header-anchor" href="#global-custom-action-configuration" aria-hidden="true">#&lt;/a>
Global Custom Action Configuration
&lt;/h2>
&lt;p>Custom actions provide a reusable Gzip compression configuration that can be referenced by multiple applications.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/global-actions.webp"
alt=""
loading="lazy" width="3342" height="1668"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has a higher priority.&lt;/p>
&lt;h2 id="application-level-configuration">
&lt;a class="header-anchor" href="#application-level-configuration" aria-hidden="true">#&lt;/a>
Application-Level Configuration
&lt;/h2>
&lt;p>In the app settings, you can configure a Gzip compression policy for a specific application.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/app-settings.webp"
alt=""
loading="lazy" width="3320" height="1530"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-options">
&lt;a class="header-anchor" href="#configuration-options" aria-hidden="true">#&lt;/a>
Configuration Options
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Follow global&lt;/strong>: Use the setting from the global general configuration&lt;/li>
&lt;li>&lt;strong>Enable&lt;/strong>: Enable Gzip compression for the current application&lt;/li>
&lt;li>&lt;strong>Disable&lt;/strong>: Disable Gzip compression for the current application&lt;/li>
&lt;/ul>
&lt;h2 id="page-rule-configuration">
&lt;a class="header-anchor" href="#page-rule-configuration" aria-hidden="true">#&lt;/a>
Page Rule Configuration
&lt;/h2>
&lt;p>Page rules provide the most fine-grained control over Gzip compression, allowing configuration for specific URL paths or conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/page-rules.webp"
alt=""
loading="lazy" width="3288" height="1766"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has the highest priority.&lt;/p>
&lt;h2 id="practical-example">
&lt;a class="header-anchor" href="#practical-example" aria-hidden="true">#&lt;/a>
Practical Example
&lt;/h2>
&lt;p>The following example demonstrates the actual effect of Gzip compression.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/gzip/example.webp"
alt=""
loading="lazy" width="3350" height="1706"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="test-scenario">
&lt;a class="header-anchor" href="#test-scenario" aria-hidden="true">#&lt;/a>
Test Scenario
&lt;/h3>
&lt;p>The example configures a simple page rule that responds directly with the text &amp;ldquo;Hello World&amp;rdquo;. Because the global general configuration enables Gzip compression by default, no additional configuration is needed.&lt;/p>
&lt;h3 id="compression-effect-test">
&lt;a class="header-anchor" href="#compression-effect-test" aria-hidden="true">#&lt;/a>
Compression Effect Test
&lt;/h3>
&lt;p>&lt;strong>Request with Gzip compression enabled:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -H 'Accept-Encoding: gzip' -v
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt; Accept-Encoding: gzip
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7f9e280008
&amp;lt; Content-Encoding: gzip
&amp;lt;
Warning: Binary output can mess up your terminal. Use &amp;quot;--output -&amp;quot; to tell
Warning: curl to output it to your terminal anyway, or consider &amp;quot;--output
Warning: &amp;lt;FILE&amp;gt;&amp;quot; to save to a file.
&lt;/code>&lt;/pre>
&lt;p>The response header includes &lt;code>Content-Encoding: gzip&lt;/code>, confirming that compression is in effect.&lt;/p>
&lt;p>&lt;strong>Request without Gzip compression:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -v
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Date: Fri, 30 May 2025 08:42:51 GMT
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7fac58000b
&amp;lt;
Hello World
&lt;/code>&lt;/pre>
&lt;p>When the request does not include the &lt;code>Accept-Encoding: gzip&lt;/code> header, the server returns the original, uncompressed content.&lt;/p>
&lt;h2 id="additional-notes">
&lt;a class="header-anchor" href="#additional-notes" aria-hidden="true">#&lt;/a>
Additional Notes
&lt;/h2>
&lt;p>When Gzip, Brotli, and zstd compression are enabled at the same time, the priority order is zstd &amp;gt; Brotli &amp;gt; Gzip.&lt;/p></description></item><item><title>Edge: Brotli Compression</title><link>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/brotli/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/brotli/</guid><description>
&lt;p>This document explains in detail how to configure and use Brotli compression in OpenResty Edge.&lt;/p>
&lt;h2 id="configuration-hierarchy-overview">
&lt;a class="header-anchor" href="#configuration-hierarchy-overview" aria-hidden="true">#&lt;/a>
Configuration Hierarchy Overview
&lt;/h2>
&lt;p>OpenResty Edge provides Brotli compression configuration at multiple levels. Listed from highest to lowest priority:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Page rule configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Page Rules &amp;gt; Actions &amp;gt; Enable Gateway Brotli / Set Brotli Type&lt;/li>
&lt;li>&lt;strong>Global custom action configuration (referenced by an HTTP application)&lt;/strong>: Global Configuration &amp;gt; Global Custom Actions &amp;gt; Actions &amp;gt; Enable Gateway Brotli / Set Brotli Type&lt;/li>
&lt;li>&lt;strong>App settings configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Settings &amp;gt; Brotli&lt;/li>
&lt;li>&lt;strong>Global rewrite rule configuration&lt;/strong>: Global Configuration &amp;gt; Global Rewrite Rules &amp;gt; Actions &amp;gt; Enable Gateway Brotli / Set Brotli Type&lt;/li>
&lt;li>&lt;strong>Global general configuration&lt;/strong>: Global Configuration &amp;gt; General Configuration &amp;gt; Brotli Configuration (enabled by default)&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: When multiple levels are configured at the same time, the higher-priority configuration overrides the lower-priority one.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-general-configuration">
&lt;a class="header-anchor" href="#global-general-configuration" aria-hidden="true">#&lt;/a>
Global General Configuration
&lt;/h2>
&lt;p>The global general configuration is the base configuration for Brotli compression, providing the default compression parameters for the entire system.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/global-config.webp"
alt=""
loading="lazy" width="3332" height="1718"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-parameters">
&lt;a class="header-anchor" href="#configuration-parameters" aria-hidden="true">#&lt;/a>
Configuration Parameters
&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Brotli switch&lt;/strong>&lt;/td>
&lt;td>On&lt;/td>
&lt;td>Globally enable or disable Brotli compression&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Brotli buffers&lt;/strong>&lt;/td>
&lt;td>32 x 4KB&lt;/td>
&lt;td>Size of the buffers used during compression; affects memory usage&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Brotli compression level&lt;/strong>&lt;/td>
&lt;td>6&lt;/td>
&lt;td>Compression level (1-22); a higher value gives a better compression ratio but is slower&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Brotli minimum length&lt;/strong>&lt;/td>
&lt;td>1000 bytes&lt;/td>
&lt;td>Compression is applied only when the response body exceeds this threshold&lt;br/>This limit is ignored for chunked transfer (Transfer-Encoding: chunked)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Brotli compressed content types&lt;/strong>&lt;/td>
&lt;td>See the list below&lt;/td>
&lt;td>Specifies the MIME types to compress with Brotli&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="default-compression-types">
&lt;a class="header-anchor" href="#default-compression-types" aria-hidden="true">#&lt;/a>
Default Compression Types
&lt;/h3>
&lt;p>By default, the system enables Brotli compression for the following MIME types:&lt;/p>
&lt;pre>&lt;code>text/plain
&lt;/code>&lt;/pre>
&lt;blockquote>
&lt;p>&lt;strong>Tip&lt;/strong>: The &lt;code>text/html&lt;/code> type is included in the compression scope by default and does not need to be listed here again.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-rewrite-rule-configuration">
&lt;a class="header-anchor" href="#global-rewrite-rule-configuration" aria-hidden="true">#&lt;/a>
Global Rewrite Rule Configuration
&lt;/h2>
&lt;p>Global rewrite rules let you configure Brotli compression for requests that match specific conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/global-rewrite-rules.webp"
alt=""
loading="lazy" width="3336" height="1732"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="available-actions">
&lt;a class="header-anchor" href="#available-actions" aria-hidden="true">#&lt;/a>
Available Actions
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Enable Gateway Brotli&lt;/strong>: Dynamically enable or disable Brotli compression&lt;/li>
&lt;li>&lt;strong>Set Brotli Compression Type&lt;/strong>: Customize the MIME types to compress&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: The compression types set here do not include &lt;code>text/html&lt;/code> by default. If you need to compress HTML content, add it manually.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-custom-action-configuration">
&lt;a class="header-anchor" href="#global-custom-action-configuration" aria-hidden="true">#&lt;/a>
Global Custom Action Configuration
&lt;/h2>
&lt;p>Custom actions provide a reusable Brotli compression configuration that can be referenced by multiple applications.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/global-actions.webp"
alt=""
loading="lazy" width="3340" height="1724"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has a higher priority.&lt;/p>
&lt;h2 id="application-level-configuration">
&lt;a class="header-anchor" href="#application-level-configuration" aria-hidden="true">#&lt;/a>
Application-Level Configuration
&lt;/h2>
&lt;p>In the app settings, you can configure a Brotli compression policy for a specific application.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/app-settings.webp"
alt=""
loading="lazy" width="3308" height="1426"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-options">
&lt;a class="header-anchor" href="#configuration-options" aria-hidden="true">#&lt;/a>
Configuration Options
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Follow global&lt;/strong>: Use the setting from the global general configuration&lt;/li>
&lt;li>&lt;strong>Enable&lt;/strong>: Enable Brotli compression for the current application&lt;/li>
&lt;li>&lt;strong>Disable&lt;/strong>: Disable Brotli compression for the current application&lt;/li>
&lt;/ul>
&lt;h2 id="page-rule-configuration">
&lt;a class="header-anchor" href="#page-rule-configuration" aria-hidden="true">#&lt;/a>
Page Rule Configuration
&lt;/h2>
&lt;p>Page rules provide the most fine-grained control over Brotli compression, allowing configuration for specific URL paths or conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/page-rules.webp"
alt=""
loading="lazy" width="3282" height="1778"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has the highest priority.&lt;/p>
&lt;h2 id="practical-example">
&lt;a class="header-anchor" href="#practical-example" aria-hidden="true">#&lt;/a>
Practical Example
&lt;/h2>
&lt;p>The following example demonstrates the actual effect of Brotli compression.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/brotli/example.webp"
alt=""
loading="lazy" width="3332" height="1706"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="test-scenario">
&lt;a class="header-anchor" href="#test-scenario" aria-hidden="true">#&lt;/a>
Test Scenario
&lt;/h3>
&lt;p>The example configures a simple page rule that responds directly with the text &amp;ldquo;Hello World&amp;rdquo;. Because the global general configuration enables Brotli compression by default, no additional configuration is needed.&lt;/p>
&lt;h3 id="compression-effect-test">
&lt;a class="header-anchor" href="#compression-effect-test" aria-hidden="true">#&lt;/a>
Compression Effect Test
&lt;/h3>
&lt;p>&lt;strong>Request with Brotli compression enabled:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -H 'Accept-Encoding: br' -v
* Added test.com:80:127.0.0.1 to DNS cache
* Hostname test.com was found in DNS cache
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt; Accept-Encoding: br
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Date: Fri, 30 May 2025 09:05:03 GMT
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7fd5f8000c
&amp;lt; Content-Encoding: br
&amp;lt;
* Connection #0 to host test.com left intact
�Hello World#
&lt;/code>&lt;/pre>
&lt;p>The response header includes &lt;code>Content-Encoding: br&lt;/code>, confirming that compression is in effect.&lt;/p>
&lt;p>&lt;strong>Request without Brotli compression:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -v
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Date: Fri, 30 May 2025 08:42:51 GMT
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7fac58000b
&amp;lt;
Hello World
&lt;/code>&lt;/pre>
&lt;p>When the request does not include the &lt;code>Accept-Encoding: br&lt;/code> header, the server returns the original, uncompressed content.&lt;/p>
&lt;h2 id="additional-notes">
&lt;a class="header-anchor" href="#additional-notes" aria-hidden="true">#&lt;/a>
Additional Notes
&lt;/h2>
&lt;p>When Gzip, Brotli, and zstd compression are enabled at the same time, the priority order is zstd &amp;gt; Brotli &amp;gt; Gzip.&lt;/p></description></item><item><title>Edge: Zstandard (zstd) Compression</title><link>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/zstd/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://doc.openresty.com/en/edge/edge-admin/applications/http/compression/zstd/</guid><description>
&lt;p>This document explains in detail how to configure and use Zstandard (zstd) compression in OpenResty Edge.&lt;/p>
&lt;h2 id="configuration-hierarchy-overview">
&lt;a class="header-anchor" href="#configuration-hierarchy-overview" aria-hidden="true">#&lt;/a>
Configuration Hierarchy Overview
&lt;/h2>
&lt;p>OpenResty Edge provides zstd compression configuration at multiple levels. Listed from highest to lowest priority:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Page rule configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Page Rules &amp;gt; Actions &amp;gt; Enable Gateway Zstandard / Set Zstandard Type&lt;/li>
&lt;li>&lt;strong>Global custom action configuration (referenced by an HTTP application)&lt;/strong>: Global Configuration &amp;gt; Global Custom Actions &amp;gt; Actions &amp;gt; Enable Gateway Zstandard / Set Zstandard Type&lt;/li>
&lt;li>&lt;strong>App settings configuration&lt;/strong>: Applications &amp;gt; HTTP Application &amp;gt; a specific application &amp;gt; Settings &amp;gt; Zstandard&lt;/li>
&lt;li>&lt;strong>Global rewrite rule configuration&lt;/strong>: Global Configuration &amp;gt; Global Rewrite Rules &amp;gt; Actions &amp;gt; Enable Gateway Zstandard / Set Zstandard Type&lt;/li>
&lt;li>&lt;strong>Global general configuration&lt;/strong>: Global Configuration &amp;gt; General Configuration &amp;gt; Zstandard Configuration (enabled by default)&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: When multiple levels are configured at the same time, the higher-priority configuration overrides the lower-priority one.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-general-configuration">
&lt;a class="header-anchor" href="#global-general-configuration" aria-hidden="true">#&lt;/a>
Global General Configuration
&lt;/h2>
&lt;p>The global general configuration is the base configuration for zstd compression, providing the default compression parameters for the entire system.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/global-config.webp"
alt=""
loading="lazy" width="3292" height="1792"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-parameters">
&lt;a class="header-anchor" href="#configuration-parameters" aria-hidden="true">#&lt;/a>
Configuration Parameters
&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Zstandard switch&lt;/strong>&lt;/td>
&lt;td>On&lt;/td>
&lt;td>Globally enable or disable Zstandard compression&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Zstandard buffers&lt;/strong>&lt;/td>
&lt;td>32 x 4KB&lt;/td>
&lt;td>Size of the buffers used during compression; affects memory usage&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Zstandard compression level&lt;/strong>&lt;/td>
&lt;td>6&lt;/td>
&lt;td>Compression level (1-22); a higher value gives a better compression ratio but is slower&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Zstandard minimum length&lt;/strong>&lt;/td>
&lt;td>1000 bytes&lt;/td>
&lt;td>Compression is applied only when the response body exceeds this threshold&lt;br/>This limit is ignored for chunked transfer (Transfer-Encoding: chunked)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Zstandard compressed content types&lt;/strong>&lt;/td>
&lt;td>See the list below&lt;/td>
&lt;td>Specifies the MIME types to compress with zstd&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="default-compression-types">
&lt;a class="header-anchor" href="#default-compression-types" aria-hidden="true">#&lt;/a>
Default Compression Types
&lt;/h3>
&lt;p>By default, the system enables zstd compression for the following MIME types:&lt;/p>
&lt;pre>&lt;code>text/plain text/css text/xml text/javascript text/cache-manifest
text/vtt text/x-component application/javascript application/json
application/ld+json application/xml application/xhtml+xml
application/rss+xml application/atom+xml application/manifest+json
application/x-web-app-manifest+json application/vnd.geo+json
application/vnd.ms-fontobject application/x-font-ttf application/wasm
font/opentype image/svg+xml image/bmp
&lt;/code>&lt;/pre>
&lt;blockquote>
&lt;p>&lt;strong>Tip&lt;/strong>: The &lt;code>text/html&lt;/code> type is included in the compression scope by default and does not need to be listed here again.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-rewrite-rule-configuration">
&lt;a class="header-anchor" href="#global-rewrite-rule-configuration" aria-hidden="true">#&lt;/a>
Global Rewrite Rule Configuration
&lt;/h2>
&lt;p>Global rewrite rules let you configure zstd compression for requests that match specific conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/global-rewrite-rules.webp"
alt=""
loading="lazy" width="3346" height="1722"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="available-actions">
&lt;a class="header-anchor" href="#available-actions" aria-hidden="true">#&lt;/a>
Available Actions
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Enable Gateway Zstandard&lt;/strong>: Dynamically enable or disable Zstandard compression&lt;/li>
&lt;li>&lt;strong>Set Zstandard Compression Type&lt;/strong>: Customize the MIME types to compress&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&lt;strong>Note&lt;/strong>: The compression types set here do not include &lt;code>text/html&lt;/code> by default. If you need to compress HTML content, add it manually.&lt;/p>
&lt;/blockquote>
&lt;h2 id="global-custom-action-configuration">
&lt;a class="header-anchor" href="#global-custom-action-configuration" aria-hidden="true">#&lt;/a>
Global Custom Action Configuration
&lt;/h2>
&lt;p>Custom actions provide a reusable zstd compression configuration that can be referenced by multiple applications.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/global-actions.webp"
alt=""
loading="lazy" width="3332" height="1728"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has a higher priority.&lt;/p>
&lt;h2 id="application-level-configuration">
&lt;a class="header-anchor" href="#application-level-configuration" aria-hidden="true">#&lt;/a>
Application-Level Configuration
&lt;/h2>
&lt;p>In the app settings, you can configure a zstd compression policy for a specific application.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/app-settings.webp"
alt=""
loading="lazy" width="3320" height="1794"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="configuration-options">
&lt;a class="header-anchor" href="#configuration-options" aria-hidden="true">#&lt;/a>
Configuration Options
&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Follow global&lt;/strong>: Use the setting from the global general configuration&lt;/li>
&lt;li>&lt;strong>Enable&lt;/strong>: Enable zstd compression for the current application&lt;/li>
&lt;li>&lt;strong>Disable&lt;/strong>: Disable zstd compression for the current application&lt;/li>
&lt;/ul>
&lt;h2 id="page-rule-configuration">
&lt;a class="header-anchor" href="#page-rule-configuration" aria-hidden="true">#&lt;/a>
Page Rule Configuration
&lt;/h2>
&lt;p>Page rules provide the most fine-grained control over zstd compression, allowing configuration for specific URL paths or conditions.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/page-rules.webp"
alt=""
loading="lazy" width="3286" height="1768"
/>
&lt;/p>
&lt;/p>
&lt;p>The configuration is the same as for global rewrite rules, but has the highest priority.&lt;/p>
&lt;h2 id="practical-example">
&lt;a class="header-anchor" href="#practical-example" aria-hidden="true">#&lt;/a>
Practical Example
&lt;/h2>
&lt;p>The following example demonstrates the actual effect of zstd compression.&lt;/p>
&lt;p>
&lt;p class="md__image">
&lt;img
src="https://doc.openresty.com/images/edge/edge-admin/compression/zstd/example.webp"
alt=""
loading="lazy" width="3350" height="1706"
/>
&lt;/p>
&lt;/p>
&lt;h3 id="test-scenario">
&lt;a class="header-anchor" href="#test-scenario" aria-hidden="true">#&lt;/a>
Test Scenario
&lt;/h3>
&lt;p>The example configures a simple page rule that responds directly with the text &amp;ldquo;Hello World&amp;rdquo;. Because the global general configuration enables zstd compression by default, no additional configuration is needed.&lt;/p>
&lt;h3 id="compression-effect-test">
&lt;a class="header-anchor" href="#compression-effect-test" aria-hidden="true">#&lt;/a>
Compression Effect Test
&lt;/h3>
&lt;p>&lt;strong>Request with zstd compression enabled:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -H 'Accept-Encoding: zstd' -v
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt; Accept-Encoding: zstd
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7f9e280008
&amp;lt; Content-Encoding: zstd
&amp;lt;
Warning: Binary output can mess up your terminal. Use &amp;quot;--output -&amp;quot; to tell
Warning: curl to output it to your terminal anyway, or consider &amp;quot;--output
Warning: &amp;lt;FILE&amp;gt;&amp;quot; to save to a file.
&lt;/code>&lt;/pre>
&lt;p>The response header includes &lt;code>Content-Encoding: zstd&lt;/code>, confirming that compression is in effect.&lt;/p>
&lt;p>&lt;strong>Request without zstd compression:&lt;/strong>&lt;/p>
&lt;pre>&lt;code class="language-bash">$ curl test.com/enable --resolve test.com:80:127.0.0.1 -v
* Trying 127.0.0.1:80...
* Connected to test.com (127.0.0.1) port 80 (#0)
&amp;gt; GET /enable HTTP/1.1
&amp;gt; Host: test.com
&amp;gt; User-Agent: curl/7.76.1
&amp;gt; Accept: */*
&amp;gt;
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 OK
&amp;lt; Date: Fri, 30 May 2025 08:42:51 GMT
&amp;lt; Content-Type: text/html
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Connection: keep-alive
&amp;lt; Req-ID: 0000008000046f7fac58000b
&amp;lt;
Hello World
&lt;/code>&lt;/pre>
&lt;p>When the request does not include the &lt;code>Accept-Encoding: zstd&lt;/code> header, the server returns the original, uncompressed content.&lt;/p>
&lt;h2 id="additional-notes">
&lt;a class="header-anchor" href="#additional-notes" aria-hidden="true">#&lt;/a>
Additional Notes
&lt;/h2>
&lt;p>When Gzip, Brotli, and zstd compression are enabled at the same time, the priority order is zstd &amp;gt; Brotli &amp;gt; Gzip.&lt;/p></description></item></channel></rss>