Improving website loading speed is a common topic. This article will start with Gzip and Brotli compression algorithms to understand the compression characteristics of these two compression algorithms, as well as Gzip vs Brotli, who has better compression effect.
Gzip compression algorithm
Gzip is based on the DEFLATE algorithm, which is a combination of LZ77 and Huffman encoding, and was first used for file compression on UNIX systems. Gzip encoding over HTTP protocol is a technology used to improve the performance of Web applications, which requires that both the Web server and the client (browser) must support Gzip. The current mainstream browsers, including IE6, IE7, IE8, IE9, FireFox, Google Chrome, Opera, etc., have begun to support Gzip compression. It can be seen that the use of Gzip has become an inevitable trend of Internet development.
As a very common data compression format used on the Internet, Gzip can compress ordinary plain text content to 40% of the original size, which greatly reduces the amount of repeated code and white space in website files. It also provides 9 compression levels, allowing users to fine-tune the amount and time of compression.
Gzip compression has always been the most popular for improving the performance of web applications. Until the emergence of another compression algorithm, Brotli, it became Gzip’s biggest competitor.
Brotli compression algorithm
Brotli is a compression algorithm launched by Google in September 2015. Google believes that Internet users’ time is precious and their time should not be consumed in long page loads, so compared with other compression algorithms, Brotli has higher compression efficiency. It compresses data through a variant of the LZ77 algorithm, Huffman coding, and second-order text modeling.
According to a research report released by Google, the Brotli compression algorithm has several characteristics, the most typical of which are the following three:
- For common Web resource content, Brotli’s performance is 17-25% higher than Gzip;
- When Brotli compression level is 1, the compression ratio is higher than when Gzip compression level is 9 (the highest);
- Brotli still provides very high compression rates when processing different HTML documents
Relying on its excellent compression performance, Brotli has quickly started to occupy the compression market since its launch. As can be seen from the figure below, almost all mainstream browsers except IE and Opera Mini have supported the Brotli algorithm.
Is Brotli better than Gzip?
Gzip has been crushed by Brotli in every way, there is no possibility of comparison between the two, and it seems that we do not need to consider choosing left or right at all.
It is true that Brotli has absolute advantages in terms of compression, but these advantages come at other costs. The time taken for a Brotli compression operation increases with the compression level. In short, Brotli needs more computing power, and we all know that the increase in computing power demand represents an increase in the cost of equipment and software facilities. In addition, Brotli requires that browsers must support the use of HTTPS, which is why he has less browser support than Gzip. After all, Gzip supports both HTTP and HTTPS.
On the one hand, the compression effect is excellent, but the user may not be able to access the website due to the unsupported browser. On the other hand, the browser supports but the compression effect is slightly weaker, and the user takes a little longer to load the webpage. A dilemma appears on the website. in front of the operator.
Smart friends may say: “Not all users can use HTTPS, but isn’t there a functional judgment? Can’t the compression algorithm be this automatic judgment? Let those who can use Brotli use Brotli, and those who can’t use Gzip .” This technology has been supported in Cloudflare , Tencent Cloud CDN , and Paiyun CDN , etc.
Note: Images should not be Gzip or Brotli compressed as they are already compressed and compressing again will make them larger.