{"id":3619,"date":"2025-12-28T21:26:13","date_gmt":"2025-12-28T18:26:13","guid":{"rendered":"https:\/\/www.dchost.com\/blog\/brotli-and-gzip-compression-settings-for-faster-core-web-vitals\/"},"modified":"2026-11-04T18:54:07","modified_gmt":"2026-11-04T15:54:07","slug":"brotli-gzip-compression-settings","status":"publish","type":"post","link":"https:\/\/www.dchost.com\/blog\/en\/brotli-gzip-compression-settings\/","title":{"rendered":"Brotli and Gzip: Nginx, Apache and LiteSpeed Setup"},"content":{"rendered":"<div class=\"dchost-blog-content-wrapper\"><p>Sending HTML, CSS and JavaScript uncompressed can slow page loading even when the server is not overloaded. Configuring <strong>Brotli and Gzip compression settings<\/strong> on Nginx, Apache or LiteSpeed can reduce transfer size and help LCP. TTFB is a related diagnostic metric, not a Core Web Vital, and aggressive dynamic compression can increase it.<\/p>\n<p>In this article, we will focus on practical, real-world tuning. We will look at how compression affects Core Web Vitals, when Brotli is better than Gzip (and when it is not), and how to configure each major web server while measuring transfer savings against CPU cost. The examples cover configurations relevant to shared hosting, <a href=\"https:\/\/www.dchost.com\/vps\">VPS<\/a>, <a href=\"https:\/\/www.dchost.com\/dedicated-server\">dedicated server<\/a>s and colocation environments; which settings you can change depends on your administrative access.<\/p>\n<div id=\"toc_container\" role=\"navigation\" aria-label=\"Table of Contents\" data-nosnippet class=\"toc_transparent no_bullets toc_numbered toc_title_center\"><p class=\"toc_title\">\u0130\u00e7indekiler<\/p><ul class=\"toc_list\"><li><a href=\"#How_Compression_Affects_Core_Web_Vitals\"><span class=\"toc_number toc_depth_1\">1.<\/span> How Compression Affects Core Web Vitals<\/a><\/li><li><a href=\"#Brotli_vs_Gzip_What_You_Really_Need_to_Know\"><span class=\"toc_number toc_depth_1\">2.<\/span> Brotli vs Gzip: What You Really Need to Know<\/a><ul><li><a href=\"#Compression_efficiency_and_CPU_cost\"><span class=\"toc_number toc_depth_2\">2.1.<\/span> Compression efficiency and CPU cost<\/a><\/li><li><a href=\"#Browser_support_and_HTTPS_considerations\"><span class=\"toc_number toc_depth_2\">2.2.<\/span> Browser support and HTTPS considerations<\/a><\/li><li><a href=\"#What_to_compress_and_what_not_to\"><span class=\"toc_number toc_depth_2\">2.3.<\/span> What to compress (and what not to)<\/a><\/li><\/ul><\/li><li><a href=\"#Tuning_Brotli_and_Gzip_on_Nginx\"><span class=\"toc_number toc_depth_1\">3.<\/span> Tuning Brotli and Gzip on Nginx<\/a><ul><li><a href=\"#Step_1_Enable_modules\"><span class=\"toc_number toc_depth_2\">3.1.<\/span> Step 1: Enable modules<\/a><\/li><li><a href=\"#Step_2_Baseline_Gzip_settings\"><span class=\"toc_number toc_depth_2\">3.2.<\/span> Step 2: Baseline Gzip settings<\/a><\/li><li><a href=\"#Step_3_Brotli_settings_for_dynamic_responses\"><span class=\"toc_number toc_depth_2\">3.3.<\/span> Step 3: Brotli settings for dynamic responses<\/a><\/li><li><a href=\"#Step_4_Precompressed_static_assets\"><span class=\"toc_number toc_depth_2\">3.4.<\/span> Step 4: Precompressed static assets<\/a><\/li><li><a href=\"#Step_5_Testing_Nginx_compression\"><span class=\"toc_number toc_depth_2\">3.5.<\/span> Step 5: Testing Nginx compression<\/a><\/li><\/ul><\/li><li><a href=\"#Tuning_Brotli_and_Gzip_on_Apache_mod_deflate_mod_brotli\"><span class=\"toc_number toc_depth_1\">4.<\/span> Tuning Brotli and Gzip on Apache (mod_deflate, mod_brotli)<\/a><ul><li><a href=\"#Step_1_Enable_the_modules\"><span class=\"toc_number toc_depth_2\">4.1.<\/span> Step 1: Enable the modules<\/a><\/li><li><a href=\"#Step_2_Gzip_mod_deflate_configuration\"><span class=\"toc_number toc_depth_2\">4.2.<\/span> Step 2: Gzip (mod_deflate) configuration<\/a><\/li><li><a href=\"#Step_3_Brotli_mod_brotli_configuration\"><span class=\"toc_number toc_depth_2\">4.3.<\/span> Step 3: Brotli (mod_brotli) configuration<\/a><\/li><li><a href=\"#Step_4_htaccess_example\"><span class=\"toc_number toc_depth_2\">4.4.<\/span> Step 4: .htaccess example<\/a><\/li><li><a href=\"#Step_5_Testing_Apache_compression\"><span class=\"toc_number toc_depth_2\">4.5.<\/span> Step 5: Testing Apache compression<\/a><\/li><\/ul><\/li><li><a href=\"#Brotli_and_Gzip_on_LiteSpeedOpenLiteSpeed\"><span class=\"toc_number toc_depth_1\">5.<\/span> Brotli and Gzip on LiteSpeed\/OpenLiteSpeed<\/a><ul><li><a href=\"#Server-level_compression_settings\"><span class=\"toc_number toc_depth_2\">5.1.<\/span> Server-level compression settings<\/a><\/li><li><a href=\"#Virtual_host_and_context_overrides\"><span class=\"toc_number toc_depth_2\">5.2.<\/span> Virtual host and context overrides<\/a><\/li><li><a href=\"#LiteSpeed_Cache_plugin_WordPress\"><span class=\"toc_number toc_depth_2\">5.3.<\/span> LiteSpeed Cache plugin (WordPress)<\/a><\/li><\/ul><\/li><li><a href=\"#Practical_Tuning_Strategy_Across_All_Web_Servers\"><span class=\"toc_number toc_depth_1\">6.<\/span> Practical Tuning Strategy Across All Web Servers<\/a><ul><li><a href=\"#1_Prioritize_the_right_content_types\"><span class=\"toc_number toc_depth_2\">6.1.<\/span> 1. Prioritize the right content types<\/a><\/li><li><a href=\"#2_Choose_safe_compression_levels\"><span class=\"toc_number toc_depth_2\">6.2.<\/span> 2. Choose safe compression levels<\/a><\/li><li><a href=\"#3_Align_compression_with_caching_and_CDN_strategy\"><span class=\"toc_number toc_depth_2\">6.3.<\/span> 3. Align compression with caching and CDN strategy<\/a><\/li><li><a href=\"#4_Sync_with_TLS_and_HTTP_protocol_tuning\"><span class=\"toc_number toc_depth_2\">6.4.<\/span> 4. Sync with TLS and HTTP protocol tuning<\/a><\/li><li><a href=\"#5_Measure_impact_on_Core_Web_Vitals_not_just_transfer_size\"><span class=\"toc_number toc_depth_2\">6.5.<\/span> 5. Measure impact on Core Web Vitals, not just transfer size<\/a><\/li><\/ul><\/li><li><a href=\"#Choosing_the_Right_Hosting_Base_for_Brotli_and_Gzip\"><span class=\"toc_number toc_depth_1\">7.<\/span> Choosing the Right Hosting Base for Brotli and Gzip<\/a><\/li><li><a href=\"#Putting_It_All_Together\"><span class=\"toc_number toc_depth_1\">8.<\/span> Putting It All Together<\/a><\/li><\/ul><\/div>\n<h2><span id=\"How_Compression_Affects_Core_Web_Vitals\">How Compression Affects Core Web Vitals<\/span><\/h2>\n<p>Before touching configuration files, it helps to connect Brotli and Gzip to the metrics your SEO and marketing teams care about, especially <strong>Core Web Vitals<\/strong>. If you have not yet read it, our article <a href=\"https:\/\/www.dchost.com\/blog\/en\/hosting-performance-ttfb-lcp-cls\/\">Core Web Vitals and hosting: how server choices impact TTFB, LCP and CLS<\/a> is a good companion to this guide.<\/p>\n<p>The most important relationships:<\/p>\n<ul>\n<li><strong>LCP (Largest Contentful Paint)<\/strong>: Often depends on how quickly the HTML document and render-blocking CSS\/JS arrive. Smaller transfers can help when those resources are on the critical loading path; measure the resulting LCP.<\/li>\n<li><strong>TTFB (Time To First Byte)<\/strong>: Compression itself does not reduce TTFB, but overly aggressive settings can <em>increase<\/em> TTFB if the server spends too long compressing each response. Good tuning is about balancing CPU cost and size savings.<\/li>\n<li><strong>INP (Interaction to Next Paint)<\/strong>: Compression can shorten JavaScript download time, but it does not reduce the amount of JavaScript to parse or execute. Smaller transfers alone do not establish an INP improvement.<\/li>\n<li><strong>CLS<\/strong>: Compression does not directly affect layout stability. Faster CSS and font delivery alone does not guarantee fewer layout shifts.<\/li>\n<\/ul>\n<p>Transfer-size savings depend on the content mix, existing compression and chosen levels. Compare compressed and uncompressed sizes for representative text responses, then measure LCP to see whether reduced transfer time improves loading on mobile connections.<\/p>\n<h2><span id=\"Brotli_vs_Gzip_What_You_Really_Need_to_Know\">Brotli vs Gzip: What You Really Need to Know<\/span><\/h2>\n<p>Both Brotli and Gzip compress HTTP responses and are negotiated via the <code>Accept-Encoding<\/code> and <code>Content-Encoding<\/code> headers. But there are important differences you should keep in mind when tuning your stack.<\/p>\n<h3><span id=\"Compression_efficiency_and_CPU_cost\">Compression efficiency and CPU cost<\/span><\/h3>\n<p>Brotli can produce smaller files than Gzip, especially for text-based content like HTML, CSS and JavaScript; the size and CPU trade-off depends on the content, implementation and compression level. But Brotli\u2019s higher levels can be very CPU intensive. For dynamic responses you generate on every request, you must be conservative.<\/p>\n<p>Useful mental model:<\/p>\n<ul>\n<li><strong>Gzip:<\/strong> Nginx and Apache accept levels 1\u20139. A level such as 4 or 5 is a starting example to measure, not a universally optimal setting.<\/li>\n<li><strong>Brotli:<\/strong> ngx_brotli and Apache mod_brotli accept quality 0\u201311. Start with an example such as 4 or 5 and compare size, CPU and latency. LiteSpeed\/OpenLiteSpeed controls have their own scope; OpenLiteSpeed\u2019s static-file level 0 disables Brotli.<\/li>\n<\/ul>\n<p>For static files (CSS\/JS built at deploy time), you can precompress with Brotli level 9\u201311 and store the resulting <code>.br<\/code> files on disk. The CPU cost is paid once during build, not on every request.<\/p>\n<h3><span id=\"Browser_support_and_HTTPS_considerations\">Browser support and HTTPS considerations<\/span><\/h3>\n<ul>\n<li>Gzip is widely supported by desktop and mobile browsers, including many legacy clients.<\/li>\n<li>Brotli (<code>br<\/code>) is supported by all major modern browsers, but typically only over HTTPS.<\/li>\n<\/ul>\n<p>A practical negotiation strategy is:<\/p>\n<ul>\n<li>Make <strong>Brotli<\/strong> available for clients that accept it over HTTPS.<\/li>\n<li>Keep <strong>Gzip<\/strong> as a fallback for older or non-Brotli clients.<\/li>\n<\/ul>\n<p>If you are still enabling HTTP\/2 and HTTP\/3 on your servers, have a look at <a href=\"https:\/\/www.dchost.com\/blog\/en\/http-2-http-3-seo-core-web-vitals-hosting\/\">our guide on how HTTP\/2 and HTTP\/3 affect SEO and Core Web Vitals<\/a>. Compression, modern HTTP protocols and TLS settings work best when tuned together.<\/p>\n<h3><span id=\"What_to_compress_and_what_not_to\">What to compress (and what not to)<\/span><\/h3>\n<p>Compression improves performance most when applied to <strong>text-based<\/strong> responses:<\/p>\n<ul>\n<li>HTML, JSON and XML.<\/li>\n<li>CSS and JavaScript.<\/li>\n<li>SVG and suitable uncompressed fonts such as TTF\/OTF. WOFF packages font tables with optional zlib compression; WOFF2 uses Brotli. Do not add these formats to HTTP recompression lists without measuring an actual benefit.<\/li>\n<\/ul>\n<p>It is usually <strong>not<\/strong> useful, and can waste CPU or increase transfer size, to compress already-compressed binary formats:<\/p>\n<ul>\n<li>JPEG, PNG, WebP, AVIF images<\/li>\n<li>MP4, WebM videos<\/li>\n<li>ZIP and similar compressed archives; PDFs may also contain compressed content, so measure any additional savings<\/li>\n<\/ul>\n<p>Apply the policy to suitable responses, not every response merely because it is text. Compressing secrets together with attacker-influenced data over TLS can expose vulnerable applications to BREACH-style attacks; evaluate sensitive, personalized routes separately.<\/p>\n<p>If you are still sending large unoptimized images, compression alone will not save you. Combine these settings with a proper image strategy like we described in <a href=\"https:\/\/www.dchost.com\/blog\/en\/image-seo-hosting-webp-avif-cdns-and-sitemaps\/\">our WebP\/AVIF and image SEO guide<\/a>.<\/p>\n<h2><span id=\"Tuning_Brotli_and_Gzip_on_Nginx\">Tuning Brotli and Gzip on Nginx<\/span><\/h2>\n<p>Nginx is very flexible for compression, but configuration can become confusing across <code>http<\/code>, <code>server<\/code> and <code>location<\/code> blocks. The following examples show a baseline configuration to adapt to your server.<\/p>\n<h3><span id=\"Step_1_Enable_modules\">Step 1: Enable modules<\/span><\/h3>\n<p>Most modern Nginx packages ship with Gzip support by default. Brotli may require:<\/p>\n<ul>\n<li>Installing an Nginx build with Brotli support, or<\/li>\n<li>Loading a Brotli dynamic module (e.g. <code>ngx_brotli<\/code>).<\/li>\n<\/ul>\n<p>Inspect the build information and the on-disk configuration separately. The commands below do not reload Nginx:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">nginx -V\nnginx -T\nnginx -t\n<\/code><\/pre>\n<p><code>-V<\/code> prints build parameters; it does not establish whether a separately packaged dynamic module is installed and loaded. For dynamic ngx_brotli, install modules compatible with your Nginx build and verify the filter\/static <code>load_module<\/code> entries in the main context, outside <code>http<\/code>; avoid duplicate loads. <code>-T<\/code> tests and prints the configuration on disk, which may contain secrets and may differ from what existing workers loaded. Inspect it locally. After a successful <code>-t<\/code>, use your distribution\u2019s controlled reload procedure. Related TLS guidance: <a href=\"https:\/\/www.dchost.com\/blog\/en\/nginx-apache-tls-hsts-ocsp-setup\/\">TLS 1.3, OCSP stapling, HSTS preload and PFS on Nginx and Apache<\/a>.<\/p>\n<h3><span id=\"Step_2_Baseline_Gzip_settings\">Step 2: Baseline Gzip settings<\/span><\/h3>\n<p>In your main Nginx config (often <code>\/etc\/nginx\/nginx.conf<\/code>), merge the following settings into the existing <code>http {}<\/code> block. The wrapper below shows context; do not paste it inside that block:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">http {\n    gzip on;\n    gzip_comp_level 4;\n    gzip_min_length 1024;\n    gzip_proxied any;\n    gzip_vary on;\n\n    gzip_types\n        text\/plain\n        text\/css\n        text\/javascript\n        application\/javascript\n        application\/x-javascript\n        application\/json\n        application\/xml\n        application\/rss+xml\n        application\/atom+xml\n        application\/xhtml+xml\n        application\/xml+rss\n        image\/svg+xml\n        font\/ttf\n        font\/otf;\n\n    # ... rest of your http config ...\n}\n<\/code><\/pre>\n<p>Notes:<\/p>\n<ul>\n<li><strong>gzip_comp_level 4:<\/strong> An example starting value. Compare additional byte savings with CPU and latency before raising it.<\/li>\n<li><strong>gzip_min_length 1024:<\/strong> The threshold is determined only from the response <code>Content-Length<\/code>. It does not guarantee that every response shorter than 1024 bytes will be excluded when its length is unknown.<\/li>\n<li><strong>gzip_vary on:<\/strong> Enables the Accept-Encoding variation header used by the relevant Nginx compression handlers.<\/li>\n<li><strong>gzip_proxied any:<\/strong> Here Nginx identifies a proxied request by its <code>Via<\/code> request header; <code>any<\/code> permits compression for these requests. Evaluate sensitive responses separately.<\/li>\n<\/ul>\n<h3><span id=\"Step_3_Brotli_settings_for_dynamic_responses\">Step 3: Brotli settings for dynamic responses<\/span><\/h3>\n<p>Once Brotli is available, merge these settings into the same <code>http<\/code> block, retaining the earlier Gzip settings including <code>gzip_vary on<\/code>:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">http {\n    # Existing gzip settings ...\n\n    brotli on;\n    brotli_comp_level 4;\n    brotli_types\n        text\/plain\n        text\/css\n        text\/javascript\n        application\/javascript\n        application\/x-javascript\n        application\/json\n        application\/xml\n        application\/rss+xml\n        application\/atom+xml\n        application\/xhtml+xml\n        application\/xml+rss\n        image\/svg+xml\n        font\/ttf\n        font\/otf;\n}\n<\/code><\/pre>\n<p>This configuration:<\/p>\n<ul>\n<li>Brotli quality 4 is an example to measure against CPU and transfer size.<\/li>\n<li>The prior Gzip configuration remains available for clients that accept it; a response is still subject to each handler\u2019s eligibility checks.<\/li>\n<li>ngx_brotli also supports <code>brotli_min_length<\/code>; like the Gzip setting, it uses a known <code>Content-Length<\/code>. If you choose 1024, apply it in the same HTTP context and do not treat it as an unconditional cutoff for unknown-length responses.<\/li>\n<\/ul>\n<p>For very busy dynamic sites, you can even start with <strong>brotli_comp_level 3<\/strong> and test CPU load.<\/p>\n<h3><span id=\"Step_4_Precompressed_static_assets\">Step 4: Precompressed static assets<\/span><\/h3>\n<p>For a build directory you control, generate matching <code>.br<\/code> and <code>.gz<\/code> files before deployment. Install the Brotli and GNU gzip\/find tools first. This example retains original files and replaces existing compressed counterparts. Each <code>find<\/code> returns a failing status if any compression invocation fails, but may process further files before returning; <code>set -e<\/code> then stops the script. Run it in the project containing <code>dist<\/code>, and deploy only after both commands succeed:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">set -eu\n\nfind dist -type f \\( -name &#039;*.js&#039; -o -name &#039;*.css&#039; -o -name &#039;*.html&#039; \\) \\\n  -exec brotli -f -q 10 {} +\n\nfind dist -type f \\( -name &#039;*.js&#039; -o -name &#039;*.css&#039; -o -name &#039;*.html&#039; \\) \\\n  -exec gzip -f -k -9 {} +\n<\/code><\/pre>\n<p>Merge the following into the existing Nginx <code>http<\/code> block, retaining <code>gzip_vary on<\/code>. The separate <code>ngx_http_gzip_static_module<\/code> and ngx_brotli static module must be available; gzip_static is not built by default:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">http {\n    gzip_static on;    # Use file.js.gz if it exists\n    brotli_static on;  # Use file.js.br if it exists\n}\n<\/code><\/pre>\n<p>With <code>on<\/code>, the static handlers check whether the client accepts the encoding. Avoid <code>always<\/code> for this negotiation pattern. Publish the original and compressed files from the same build together; a leftover compressed counterpart may contain obsolete content. Precompression moves encoding work to build time, while request processing and delivery still have costs. Measure the actual benefit.<\/p>\n<h3><span id=\"Step_5_Testing_Nginx_compression\">Step 5: Testing Nginx compression<\/span><\/h3>\n<p>Use real GET requests to representative eligible resources. <code>-I<\/code> sends HEAD and does not prove that a dynamic response body was compressed. Replace the example URL with your own:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">curl -sS -D - -o \/dev\/null -H &#039;Accept-Encoding: gzip&#039; https:\/\/example.com\/\ncurl -sS -D - -o \/dev\/null -H &#039;Accept-Encoding: br&#039; https:\/\/example.com\/\ncurl -sS -D - -o \/dev\/null -H &#039;Accept-Encoding: identity&#039; https:\/\/example.com\/\n<\/code><\/pre>\n<p>In the response headers, confirm:<\/p>\n<ul>\n<li>Check status, MIME type and <code>Content-Encoding<\/code> against the requested and actually eligible encoding; the identity response should remain readable without compression.<\/li>\n<li>For negotiated compressed responses, inspect <code>Vary: Accept-Encoding<\/code> and test cache variants. This header alone does not establish a CDN\u2019s cache policy.<\/li>\n<li>Headers identify the advertised encoding; verify that bodies decode correctly and compare transferred bytes with the decoded size. If a CDN is present, test its response separately from the origin.<\/li>\n<\/ul>\n<p>Then run a full-page test with tools such as PageSpeed Insights or WebPageTest. As a reference, see our guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/how-to-properly-test-your-website-speed\/\">how to properly test your website speed<\/a> so you interpret the results correctly.<\/p>\n<h2><span id=\"Tuning_Brotli_and_Gzip_on_Apache_mod_deflate_mod_brotli\">Tuning Brotli and Gzip on Apache (mod_deflate, mod_brotli)<\/span><\/h2>\n<p>Apache uses <code>mod_deflate<\/code> for Gzip and <code>mod_brotli<\/code> for Brotli. MIME filtering can be permitted in <code>.htaccess<\/code>, but compression level and Brotli window settings belong to server or virtual-host configuration.<\/p>\n<h3><span id=\"Step_1_Enable_the_modules\">Step 1: Enable the modules<\/span><\/h3>\n<p>Use your distribution\u2019s module mechanism and existing module paths; the following server-context paths are examples, not installation commands. Check for existing loads and ensure <code>mod_filter<\/code> is also available before using <code>AddOutputFilterByType<\/code>:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">LoadModule deflate_module modules\/mod_deflate.so\nLoadModule brotli_module  modules\/mod_brotli.so\n<\/code><\/pre>\n<p>Before any reload, save the previous configuration and run the distribution\u2019s configuration test. For an httpd installation using these paths, the diagnostic is:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">httpd -t\n<\/code><\/pre>\n<h3><span id=\"Step_2_Gzip_mod_deflate_configuration\">Step 2: Gzip (mod_deflate) configuration<\/span><\/h3>\n<p>Place this Gzip configuration in the global server configuration or a virtual host. After editing, repeat the syntax test; use the package or control panel\u2019s supported graceful reload procedure only if that test succeeds:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">&lt;IfModule mod_deflate.c&gt;\n    AddOutputFilterByType DEFLATE text\/plain text\/html text\/xml text\/css text\/javascript application\/javascript application\/x-javascript application\/json application\/xml application\/xhtml+xml application\/rss+xml application\/atom+xml image\/svg+xml font\/ttf font\/otf\n\n    # Optional exclusions for already compressed request paths\n    SetEnvIfNoCase Request_URI &quot;\\.(?:gif|jpe?g|png|webp|avif|mp4|mp3|ogg|zip|gz|bz2|rar|woff2?)$&quot; no-gzip\n\n    DeflateCompressionLevel 4\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n<p>The MIME allowlist targets suitable responses, while the optional path exclusion uses <code>mod_setenvif<\/code>; confirm that module if you retain the line. <code>mod_deflate<\/code> adds <code>Vary: Accept-Encoding<\/code> itself. Additional request-header-dependent exclusions require their own variation policy. Quality 4 is an example, not proof of lower latency on your server.<\/p>\n<h3><span id=\"Step_3_Brotli_mod_brotli_configuration\">Step 3: Brotli (mod_brotli) configuration<\/span><\/h3>\n<p><code>mod_brotli<\/code> is available in Apache 2.4.26 and later and must be enabled in the installed package. These quality\/window directives belong to server or virtual-host configuration:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">&lt;IfModule mod_brotli.c&gt;\n    BrotliCompressionQuality 4\n    BrotliCompressionWindow 18\n    AddOutputFilterByType BROTLI_COMPRESS text\/plain text\/html text\/xml text\/css text\/javascript application\/javascript application\/json application\/xml application\/xhtml+xml application\/rss+xml application\/atom+xml image\/svg+xml font\/ttf font\/otf\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n<p><code>BrotliCompressionWindow<\/code> accepts 10\u201324 and represents 2 to that power bytes; the default 18 is 256 KiB. A larger value can use more memory per connection. <code>mod_brotli<\/code> adds its Accept-Encoding variation header. Having both compression modules loaded does not establish Brotli preference: inspect the effective filter chain and test <code>br<\/code>, <code>gzip<\/code> and identity requests for correct encoding without recompressing an already encoded response.<\/p>\n<h3><span id=\"Step_4_htaccess_example\">Step 4: .htaccess example<\/span><\/h3>\n<p>If only <code>.htaccess<\/code> is available, use MIME filtering only where the server permits it. <code>AddOutputFilterByType<\/code> requires <code>mod_filter<\/code>, the selected compression module and appropriate <code>AllowOverride FileInfo<\/code> or <code>AllowOverrideList<\/code> permission. Coordinate these examples with any existing filters:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">&lt;IfModule mod_deflate.c&gt;\n    AddOutputFilterByType DEFLATE text\/html text\/plain text\/css application\/javascript application\/json image\/svg+xml\n&lt;\/IfModule&gt;\n\n&lt;IfModule mod_brotli.c&gt;\n    AddOutputFilterByType BROTLI_COMPRESS text\/html text\/plain text\/css application\/javascript application\/json image\/svg+xml\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n<p><code>DeflateCompressionLevel<\/code>, <code>BrotliCompressionQuality<\/code> and <code>BrotliCompressionWindow<\/code> are server\/virtual-host directives; do not put them in <code>.htaccess<\/code>. An <code>IfModule<\/code> wrapper does not grant a directive permission to run in another context.<\/p>\n<h3><span id=\"Step_5_Testing_Apache_compression\">Step 5: Testing Apache compression<\/span><\/h3>\n<p>Again, use <code>curl<\/code> or browser DevTools:<\/p>\n<ul>\n<li>Look at the <strong>Network<\/strong> tab, check a CSS or JS file, and verify <code>Content-Encoding<\/code> is <code>gzip<\/code> or <code>br<\/code>.<\/li>\n<li>Compare transferred bytes with the decoded resource size, then measure CPU, TTFB and loading results. Do not assume every resource will become significantly smaller.<\/li>\n<\/ul>\n<h2><span id=\"Brotli_and_Gzip_on_LiteSpeedOpenLiteSpeed\">Brotli and Gzip on LiteSpeed\/OpenLiteSpeed<\/span><\/h2>\n<p>LiteSpeed Web Server documents compression of static and dynamic responses. OpenLiteSpeed\u2019s panel documentation separates dynamic GZIP controls from Brotli for static files; do not assume identical behavior from similar names. The WordPress LiteSpeed Cache plugin primarily communicates application cache rules to the server cache engine.<\/p>\n<h3><span id=\"Server-level_compression_settings\">Server-level compression settings<\/span><\/h3>\n<p>With authorized access to the installed product\u2019s WebAdmin console, open its compression controls:<\/p>\n<ul>\n<li><strong>LiteSpeed Web Server:<\/strong> <code>Configuration &gt; Server &gt; Tuning<\/code>.<\/li>\n<li><strong>OpenLiteSpeed:<\/strong> <code>Server Configuration &gt; Tuning<\/code>.<\/li>\n<\/ul>\n<p>Key directives:<\/p>\n<ul>\n<li><strong>Enable Compression:<\/strong> The master switch must be enabled; set compressible MIME types and evaluate static and dynamic content separately.<\/li>\n<li><strong>LiteSpeed Web Server:<\/strong> Check the dynamic compression switch, static file size bounds and the relevant static\/dynamic quality controls.<\/li>\n<li><strong>OpenLiteSpeed:<\/strong> Check <code>Enable Dynamic GZIP Compression<\/code> and <code>GZIP Compression Level (Dynamic Content)<\/code>, whose range is 1\u20139. <code>Brotli Compression Level (Static File)<\/code> is a separate setting; 0 disables Brotli.<\/li>\n<li>Adapt levels by measurement. Apply the product\u2019s save\/reload procedure and verify the resulting GET responses.<\/li>\n<\/ul>\n<p>Inspect the encoding returned for clients with different Accept-Encoding values. MIME matching, response type, master switches and installed-product behavior all affect whether compression is applied.<\/p>\n<h3><span id=\"Virtual_host_and_context_overrides\">Virtual host and context overrides<\/span><\/h3>\n<p>OpenLiteSpeed exposes GZIP and Brotli switches under each virtual host\u2019s General settings. The following is a panel checklist for adjusting compression for that entire virtual host; it is not a configuration-file fragment or a directory-only exception:<\/p>\n<ol>\n<li>Open the intended virtual host\u2019s <strong>General<\/strong> settings.<\/li>\n<li>Set <strong>Enable GZIP Compression<\/strong> and <strong>Enable Brotli Compression<\/strong> as required for that host.<\/li>\n<li>Save and follow the product\u2019s apply procedure; verify representative GET responses.<\/li>\n<\/ol>\n<p>For a download directory, prefer suitable MIME exclusions or verify the exact directory\/context mechanism in the installed product. Disabling a virtual host affects more than that directory. OpenLiteSpeed\u2019s server master switch overrides its virtual-host switches; do not expect a virtual-host override to re-enable a server-wide disabled feature.<\/p>\n<h3><span id=\"LiteSpeed_Cache_plugin_WordPress\">LiteSpeed Cache plugin (WordPress)<\/span><\/h3>\n<p>Use <strong>LiteSpeed Cache &gt; Cache<\/strong> to manage application caching where an LSCache server component is available. Do not treat Browser or Page Optimization settings as evidence that HTTP Brotli\/Gzip is enabled; inspect the server\u2019s controls and the actual response.<\/p>\n<ul>\n<li>Manage HTTP compression through the server configuration or hosting provider.<\/li>\n<li>Use the plugin\u2019s documented cache and asset-optimization features for their separate purposes; installing the plugin alone does not enable server-side page caching on every web server.<\/li>\n<li>After changes, check encoding and cache behavior together, including personalized pages that must not be shared between users.<\/li>\n<\/ul>\n<p>For a broader performance strategy on LiteSpeed-based hosting, see our article on <a href=\"https:\/\/www.dchost.com\/blog\/en\/speed-up-wordpress-with-litespeed-cache-on-shared-hosting\/\">speeding up WordPress with LiteSpeed Cache on shared hosting<\/a>.<\/p>\n<h2><span id=\"Practical_Tuning_Strategy_Across_All_Web_Servers\">Practical Tuning Strategy Across All Web Servers<\/span><\/h2>\n<p>Regardless of whether you use Nginx, Apache or LiteSpeed, the high-level strategy is very similar. Use the following measurement-led workflow for your own configuration.<\/p>\n<h3><span id=\"1_Prioritize_the_right_content_types\">1. Prioritize the right content types<\/span><\/h3>\n<p>Focus on compressing:<\/p>\n<ul>\n<li><strong>HTML and JSON<\/strong>: these control the start of rendering and data APIs.<\/li>\n<li><strong>Critical CSS and JavaScript<\/strong>: anything that blocks the first render.<\/li>\n<li><strong>SVG icons and suitable uncompressed fonts<\/strong>: evaluate their transfer cost; do not automatically recompress WOFF\/WOFF2.<\/li>\n<\/ul>\n<p>Skip or explicitly exclude:<\/p>\n<ul>\n<li>Images (JPEG\/PNG\/WebP\/AVIF)<\/li>\n<li>Videos<\/li>\n<li>Archives (ZIP, GZ, RAR, etc.)<\/li>\n<\/ul>\n<h3><span id=\"2_Choose_safe_compression_levels\">2. Choose safe compression levels<\/span><\/h3>\n<p>These are example values to test, not DCHost provisioning defaults or measured recommendations for your workload:<\/p>\n<ul>\n<li><strong>Gzip<\/strong>: level 4 for dynamic content; 6\u20139 for precompressed static files generated at build time.<\/li>\n<li><strong>Brotli<\/strong>: level 4 for dynamic; 9\u201311 for precompressed static assets.<\/li>\n<\/ul>\n<p>Record both the baseline and changed configuration, then monitor:<\/p>\n<ul>\n<li>CPU usage under peak traffic.<\/li>\n<li>Average TTFB from monitoring tools.<\/li>\n<li>Error rates (e.g. timeouts if compression is too heavy for the hardware).<\/li>\n<\/ul>\n<p>If CPU is underutilized, you can gently raise levels. If CPU saturates during spikes, reduce them.<\/p>\n<h3><span id=\"3_Align_compression_with_caching_and_CDN_strategy\">3. Align compression with caching and CDN strategy<\/span><\/h3>\n<p>Plan compression together with cache headers and any CDN; their benefits depend on the workload and actual cache policy. For detailed header rules, see <a href=\"https:\/\/www.dchost.com\/blog\/en\/browser-cdn-caching-wordpress-laravel-spas\/\">our guide to HTTP Cache-Control, ETag and CDN rules<\/a>, and for the CDN concept itself, the article <a href=\"https:\/\/www.dchost.com\/blog\/en\/what-is-a-cdn-and-when-do-you-really-need-one\/\">What is a CDN and when do you really need one<\/a>.<\/p>\n<p>Key alignment points:<\/p>\n<ul>\n<li><strong>Cache hits:<\/strong> A response served completely at the CDN can avoid the corresponding origin request; cache misses and revalidation still need separate analysis.<\/li>\n<li><strong>Vary:<\/strong> Retain appropriate Accept-Encoding variation and verify the CDN\u2019s encoding\/cache policy. Vary alone does not prove how a particular CDN stores variants.<\/li>\n<li><strong>Warm-up:<\/strong> If you warm public cacheable pages, limit the rate and use anonymous requests; never populate shared cache with personalized session content.<\/li>\n<\/ul>\n<h3><span id=\"4_Sync_with_TLS_and_HTTP_protocol_tuning\">4. Sync with TLS and HTTP protocol tuning<\/span><\/h3>\n<p>Browser Brotli support is commonly associated with HTTPS, but compression is distinct from TLS and HTTP version selection. Review the protocol configuration for the clients you support:<\/p>\n<ul>\n<li>Use a supported TLS policy, such as appropriately configured TLS 1.2\/1.3, and test renewal.<\/li>\n<li>Evaluate HTTP\/2 and HTTP\/3 where supported; neither guarantees better results for every connection.<\/li>\n<li>Check certificate-specific OCSP support before enabling stapling. Current Let\u2019s Encrypt certificates use CRL-based revocation information after the OCSP service retirement; do not assume a responder exists. Evaluate session resumption separately.<\/li>\n<\/ul>\n<p>We covered these in depth in our article on <a href=\"https:\/\/www.dchost.com\/blog\/en\/nginx-apache-tls-hsts-ocsp-setup\/\">TLS 1.3, OCSP stapling and modern HTTPS on Nginx and Apache<\/a>. Measure each change; combining these features does not guarantee a visible Core Web Vitals improvement.<\/p>\n<h3><span id=\"5_Measure_impact_on_Core_Web_Vitals_not_just_transfer_size\">5. Measure impact on Core Web Vitals, not just transfer size<\/span><\/h3>\n<p>After enabling or tuning compression, measure:<\/p>\n<ul>\n<li><strong>LCP<\/strong>: particularly on mobile connections and from key geographies where your users are.<\/li>\n<li><strong>TTFB<\/strong>: ensure it does not regress due to CPU overhead.<\/li>\n<li><strong>Total bytes transferred<\/strong> for HTML\/CSS\/JS.<\/li>\n<\/ul>\n<p>Use controlled lab tests alongside available field data from PageSpeed Insights, Search Console or RUM. Keep cache state, connection profile and test locations comparable. A smaller transfer is useful only when its benefit justifies added CPU, memory and latency; no fixed percentage is required for success.<\/p>\n<h2><span id=\"Choosing_the_Right_Hosting_Base_for_Brotli_and_Gzip\">Choosing the Right Hosting Base for Brotli and Gzip<\/span><\/h2>\n<p>Compression is mostly a configuration issue, but hardware and hosting architecture still matter. On very weak or oversold servers, high compression levels can push CPU to 100% during traffic spikes and actually harm performance.<\/p>\n<p>When evaluating hosting capacity for dynamic applications such as WordPress, WooCommerce, Laravel or Node.js, consider:<\/p>\n<ul>\n<li><strong>vCPU capacity<\/strong>: enough headroom for PHP\/Node plus Brotli\/Gzip work.<\/li>\n<li><strong>Storage latency and capacity<\/strong>: measure delivery of precompressed assets and allow space for originals and compressed variants; an NVMe label alone does not establish performance.<\/li>\n<li><strong>Network throughput<\/strong>: so you can benefit fully from reduced payloads.<\/li>\n<\/ul>\n<p>If your site is growing, it may be time to move from basic shared hosting to a VPS or even a dedicated server, where the control you receive depends on management scope, permissions, installed software and licensing. Moving plans alone does not make every example applicable. For a deeper dive into planning resources for modern PHP apps, see our guides on <a href=\"https:\/\/www.dchost.com\/blog\/en\/wordpress-server-tuning-php-redis-mysql\/\">server-side optimization for WordPress<\/a> and on <a href=\"https:\/\/www.dchost.com\/blog\/en\/nvme-vps-iops-latency-storage-tests\/\">NVMe VPS hosting and where the speed really comes from<\/a>.<\/p>\n<h2><span id=\"Putting_It_All_Together\">Putting It All Together<\/span><\/h2>\n<p>Brotli and Gzip can reduce transfer size for suitable responses, but a configuration should be judged by measured loading performance and server cost. Preserve the previous settings so that a regression can be reversed.<\/p>\n<p>A practical completion checklist is:<\/p>\n<ul>\n<li>Confirm the installed modules, permissions and actual configuration contexts.<\/li>\n<li>Enable supported encodings for appropriate content and verify Gzip, Brotli and identity behavior; do not assume an encoding preference from module load order.<\/li>\n<li>Choose levels by transfer size, CPU and latency; generate expensive static variants during a controlled build.<\/li>\n<li>Publish matching originals and compressed variants together and check CDN\/cache behavior.<\/li>\n<li>Compare LCP and TTFB with the baseline, then expand only when the observed behavior is correct.<\/li>\n<\/ul>\n<p>For a DCHost plan, confirm which server settings you can manage and which are handled by the provider. Choose CPU capacity, storage and network resources around measured application demand; do not infer a particular compression setup, migration service or performance result from the plan category.<\/p>\n<p>Use the guide to make one controlled change at a time: record the baseline, test the configuration, verify real responses and compare performance. Compression is one part of delivery performance; reaching good Core Web Vitals also depends on the application and front-end workload.<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Configure HTTP compression around your server, modules and permissions. Compare MIME selection, precompressed assets, CPU cost and real GET responses before changing production settings.<\/p>\n","protected":false},"author":1,"featured_media":12526,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":["post-3619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/comments?post=3619"}],"version-history":[{"count":8,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3619\/revisions"}],"predecessor-version":[{"id":12528,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3619\/revisions\/12528"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media\/12526"}],"wp:attachment":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media?parent=3619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/categories?post=3619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/tags?post=3619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}