Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:cache:common:gzip-brotli-automatic-conversion [2018/08/17 18:43]
Jackson Zhang created
litespeed_wiki:cache:common:gzip-brotli-automatic-conversion [2020/03/31 02:34] (current)
Joshua Reynolds [LSWS v5.3 Brotli and gzip Enhancements] link to gzip page
Line 1: Line 1:
-====== Brotli ​compression for dynamic responses ​and automatic GZIP and BROTLI conversion for cached pages ====== +====== ​LSWS v5.3 Brotli and gzip Enhancements ​====== 
-LSWS has added brotli compression support for a while, but it used to be for static files onlyStarting with LSWS 5.3, Brotli ​compression for dynamic responses ​has been addedAlsoLSWS will do automatic ​GZIP and BROTLI ​conversion for cached pages.+LiteSpeed Web Server ​has included [[litespeed_wiki:​config:​brotli:​start|brotli]] compression support for a while, but it was only for static files. ​As of v5.3, brotli ​compression ​has been added for dynamic responses. ​Additionally, automatic ​[[litespeed_wiki:​config:​gzip-compression|gzip]] ​and brotli ​conversion ​has been added for cached pages.
  
-===== Brotli ​compression ​for dynamic pages ===== +===== Brotli ​Compression ​for Dynamic Pages ===== 
-To test brotli ​compression,​ the client (browser) must be Brotli compatible. Google Chrome: Chrome 49+ and Mozilla Firefox: Firefox 44+ are good for brotli ​testing. Also, you will need to run test over an HTTPS connection, can not be HTTP connection. ​+To test Brotli ​compression,​ the client (browser) must be Brotli compatible. Google Chrome ​v49+ and Mozilla Firefox ​v44+ are both good candidates ​for Brotli ​testing. Also, you will need to run tests over an HTTPS connection. It cannot ​be an HTTP connection. ​
  
-The following page header ​shows "​Content-Encoding:​gzip", since it is only HTTP connection for the same domain.+Negotiation is done via the ''​Accept-Encoding:​ br''​ request ​header. Servers can add "br" to ''​Content-Encoding: ​br''​ to encode a response with Brotli.
  
-{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion1.png?​800 |}} +The following page header shows ''​Content-Encoding:​gzip'',​ since it is only an HTTP connection.
-When we test HTTPS connection for the same domain, the header shows "Content-Encoding:​br".+
  
-{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion2.png?800 |}}+{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion1.png?600 |}}
  
-You should test a page without ESI on it, such as a https wordpress page as indicated as above. LSWS will use brotli compression as default instead of gzip as far as client supports it(make sure to test HTTPS connection ​instead of HTTP). However, for ESI pages, gzip compression will be used since LiteSpeed cached ESI pages are optimized ​for gzipsuch as a Magento page+When we test an HTTPS connection for the same domainthe header shows ''​Content-Encoding:​br''​.
  
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion2.png?​600 |}}
 +
 +Good pages to test include any HTTP WordPress pages without ESI on them, like above. LSWS will use Brotli compression by default, instead of gzip, as long as the client supports it. (Make sure to test an HTTPS connection instead of HTTP.) For ESI pages, however, gzip compression will be used. This is because LiteSpeed-cached ESI pages, such as on a Magento site, are optimized for gzip. 
 +
 +The following image shows ''​Accept-Encoding:​ br''​ is sent, but ''​Content-Encoding:​gzip''​ is returned since it is an ESI Magento page.
 +
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion3.png?​600 |}}
 +
 +===== Automatic gzip and Brotli Conversion for Cached Pages =====
 +
 +LSWS 5.3 can cache both Brotli- and gzip-compressed copy, convert between them, and cache the result. ​
 +
 +To save on disk space, there is a hit limit before LSWS is triggered to save the other compression result. For example, if the Brotli version is cached, and the client requests gzip, LSWS will dynamically decompress the Brotli version, re-compress as gzip, serve the resquest, and discard the result. If there are more than 10 such requests, the gzip version will be cached, and the next request will be served directly from cache. To avoid misleading benchmark results, LSWS and ADC will immediately cache the result for a different compression version, if a benchmark tool has been detected via User-Agent. When Accept-Encoding request header is not set, the result will not dynamically expand. Currently, "​Apache Bench" is detected.
 +
 +To test the cache engine, we will use two browsers: Chrome, using Brotli encoding, and Firefoc using gzip encoding.
 +
 +First, use Chrome. You will see ''​Content-Encoding:​ br''​ on both the first visit cache miss and the second visit cache hit.
 +
 +First Visit:
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion4.png?​600 |}}
 +
 +Second Visit:
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion5.png?​600 |}}
 +
 +Next, use Firefox, and manipulate Accept-Encoding to gzip only: ''​Accept-Encoding:​gzip''​.
 +
 +On the first visit, you will still see ''​Content-Encoding:​ br''​ since it is the default setting. Also, it is a cached page. 
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion6.png?​600 |}}
 +
 +Edit and press **Send** to change the header to ''​Accept-Encoding:​gzip'':​
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion7.png?​600 |}}
 +
 +After sending, you will see the cached page has been auto converted to gzip compression,​ even though the initial cached version was Brotli compressed.
 +{{ :​litespeed_wiki:​cache:​common:​lsws5.3-br-gzip-auto-convertion8.png?​600 |}}
  
  • Admin
  • Last modified: 2018/08/17 18:43
  • by Jackson Zhang