If I use Apache
Posted: Wed Dec 18, 2024 8:20 am
Are you looking for free ways to make your website faster? One way every website owner can get some free speed is to turn on compression on the server. When both the web server and the browser you're talking to understand a common compression algorithm, then the data actually being sent over the wire can be compressed. Compressed data is smaller. Smaller data is received faster.
What is compression?
When you enter a URL into your browser, the browser starts a conversation with the server and one of the things it tells the server is whether it can decompress content and, if so, what compression “algorithms” it understands.
The server listens, and if you have compression enabled and it knows one of the compression algorithms that the browser does, it will compress all the data and send it to the browser.
Most modern web browsers understand or “accept” content encoded in one of three algorithms:
Deflate
Gzip
Brotli
When a web browser contacts a server, it sends a header that looks like this:
Accept encoding: br, gzip
This tells the server that it understands Brotli (br) or Gzip (gzip) compressed data. Servers have the option to ignore this and return uncompressed data as well.
However, in general, compressed data travels faster than uncompressed data. So, your website arrives in the browser faster if the data is compressed.
Compression is mainly applied to text:
HTML
javascript
CSS
These make up a large portion of modern websites these days and all of these can be compressed using compression algorithms on the server side.
On the other hand, most image formats (jpg, png, etc.) and most audio formats (mp3) and other non-text binary files are already compressed. Compressing them won't make any difference, so regardless of the Accept-Encoding header, the servers will send them as is.
As stated above, most modern web browsers will support 3 main compression algorithms. Most servers have now migrated to one or both of the two most popular, Gzip and Brotli.
What is Gzip compression?
The two most common compression algorithms are Gzip and Brotli. Gzip is the older and more common of the two. It was written by Jean-loup Gailly and Mark Adler. The initial beta version was done in 1992. The first real version, version 1.0, was released in early 1993. In 1992, just as the web was starting to become a mainstream concept for most people.
Gzip was designed as a general-purpose compression library. The theories behind Gzip were based on the previous compression algorithm, DEFLATE.
Due to its popularity, and the fact that it is very good at making files small, it is still widely used today both in different operating systems and as a primary compression algorithm for web servers.
What is Brotli compression?
Brotli was developed by Google employees Jyrki Alakuijala and Zoltán Szabadka in 2013. Originally, Google was looking for a better way to compress WOT files which are web fonts.
Gzip was originally intended to compress files and has been adapted to compress streams so that it can work on the web. Brotli, on the other hand, was designed from the ground up to compress streams. This makes it a better choice for web servers to compress content before transmitting it to a browser.
In 2015, Google released the Brotli specification for HTTP. In addition to specifying how the browser should notify the server that it can decompress Brotli by sending a “Content-Encoding: br” header, Google engineers also made other improvements to Brotli that made it even faster at compressing web content.
What is the difference between Brotli and Gzip compression?
While both have their origins in the LZ77 algorithm, Gzip was specifically designed to compress files. The library has been incorporated into many different programs that need to compress files. The library was incorporated into web servers when content compression started to become the norm. It was one of two compression algorithms specified in RFC 2616, the HTTPS 1.1 specification. While it was not specifically designed for streaming operations like web servers, it was adapted to do so.
Brotli, on the other hand, was designed specifically for the web. Google recognized the need for a way to compress streams more efficiently, so it designed Brotli.
Both algorithms do a good job of what they were designed for. Gzip is still used on the web because it is better than nothing. However, as Brotli grows in popularity, more and more web hosts are choosing Brotli over Gzip. Given the choice of the two, Brotli is the default that many servers will use. It has been the default option on all SiteGround servers for a while now.
Check out the video below to learn more about the differences between Brotli and Gzip!
Comparative evaluation of Brotli and Gzip
When Brotli was compared to Gzip, it was found to compress the following files better:
JavaScript 14% smaller
HTML 21% smaller
CSS 17% smaller
Since Brotli was designed to compress streams on the fly, it is faster at both compressing content on the server and decompressing it in the browser than gzip. In some cases, the overall initial decompression is up to 64% faster than Gzip.
How can I enable compression on my website?
In simple terms, “turning on compression” simply means telling your web server to compress everything before sending it to a browser that has advertised that it can handle compression.
If you are a server administrator, you know how to edit configuration files. If you are not a server administrator, skip this section and go directly to the “If I am not a server administrator” section below.
If you are using the Apache web server, there are 2 steps to enable Brotli malaysia whatsapp number data compression:
First, enable the Brotli apache module. It is included by default, but it may not be enabled:
$ sudo a2enmod brotli
Next, you need to edit your web server's configuration file and tell the server what you want to apply compression to:
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
In the example above, we are telling the web server to compress:
HTML
Plain text
CSS
JavaScript
These are the main types of files that can be compressed.
What is compression?
When you enter a URL into your browser, the browser starts a conversation with the server and one of the things it tells the server is whether it can decompress content and, if so, what compression “algorithms” it understands.
The server listens, and if you have compression enabled and it knows one of the compression algorithms that the browser does, it will compress all the data and send it to the browser.
Most modern web browsers understand or “accept” content encoded in one of three algorithms:
Deflate
Gzip
Brotli
When a web browser contacts a server, it sends a header that looks like this:
Accept encoding: br, gzip
This tells the server that it understands Brotli (br) or Gzip (gzip) compressed data. Servers have the option to ignore this and return uncompressed data as well.
However, in general, compressed data travels faster than uncompressed data. So, your website arrives in the browser faster if the data is compressed.
Compression is mainly applied to text:
HTML
javascript
CSS
These make up a large portion of modern websites these days and all of these can be compressed using compression algorithms on the server side.
On the other hand, most image formats (jpg, png, etc.) and most audio formats (mp3) and other non-text binary files are already compressed. Compressing them won't make any difference, so regardless of the Accept-Encoding header, the servers will send them as is.
As stated above, most modern web browsers will support 3 main compression algorithms. Most servers have now migrated to one or both of the two most popular, Gzip and Brotli.
What is Gzip compression?
The two most common compression algorithms are Gzip and Brotli. Gzip is the older and more common of the two. It was written by Jean-loup Gailly and Mark Adler. The initial beta version was done in 1992. The first real version, version 1.0, was released in early 1993. In 1992, just as the web was starting to become a mainstream concept for most people.
Gzip was designed as a general-purpose compression library. The theories behind Gzip were based on the previous compression algorithm, DEFLATE.
Due to its popularity, and the fact that it is very good at making files small, it is still widely used today both in different operating systems and as a primary compression algorithm for web servers.
What is Brotli compression?
Brotli was developed by Google employees Jyrki Alakuijala and Zoltán Szabadka in 2013. Originally, Google was looking for a better way to compress WOT files which are web fonts.
Gzip was originally intended to compress files and has been adapted to compress streams so that it can work on the web. Brotli, on the other hand, was designed from the ground up to compress streams. This makes it a better choice for web servers to compress content before transmitting it to a browser.
In 2015, Google released the Brotli specification for HTTP. In addition to specifying how the browser should notify the server that it can decompress Brotli by sending a “Content-Encoding: br” header, Google engineers also made other improvements to Brotli that made it even faster at compressing web content.
What is the difference between Brotli and Gzip compression?
While both have their origins in the LZ77 algorithm, Gzip was specifically designed to compress files. The library has been incorporated into many different programs that need to compress files. The library was incorporated into web servers when content compression started to become the norm. It was one of two compression algorithms specified in RFC 2616, the HTTPS 1.1 specification. While it was not specifically designed for streaming operations like web servers, it was adapted to do so.
Brotli, on the other hand, was designed specifically for the web. Google recognized the need for a way to compress streams more efficiently, so it designed Brotli.
Both algorithms do a good job of what they were designed for. Gzip is still used on the web because it is better than nothing. However, as Brotli grows in popularity, more and more web hosts are choosing Brotli over Gzip. Given the choice of the two, Brotli is the default that many servers will use. It has been the default option on all SiteGround servers for a while now.
Check out the video below to learn more about the differences between Brotli and Gzip!
Comparative evaluation of Brotli and Gzip
When Brotli was compared to Gzip, it was found to compress the following files better:
JavaScript 14% smaller
HTML 21% smaller
CSS 17% smaller
Since Brotli was designed to compress streams on the fly, it is faster at both compressing content on the server and decompressing it in the browser than gzip. In some cases, the overall initial decompression is up to 64% faster than Gzip.
How can I enable compression on my website?
In simple terms, “turning on compression” simply means telling your web server to compress everything before sending it to a browser that has advertised that it can handle compression.
If you are a server administrator, you know how to edit configuration files. If you are not a server administrator, skip this section and go directly to the “If I am not a server administrator” section below.
If you are using the Apache web server, there are 2 steps to enable Brotli malaysia whatsapp number data compression:
First, enable the Brotli apache module. It is included by default, but it may not be enabled:
$ sudo a2enmod brotli
Next, you need to edit your web server's configuration file and tell the server what you want to apply compression to:
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
In the example above, we are telling the web server to compress:
HTML
Plain text
CSS
JavaScript
These are the main types of files that can be compressed.