Enabling data compression in Apache using .htaccess (DEFLATE and GZip)

Views: 4.788
Reading Time: <1 minute

In this post I will demonstrate how to compress text content in your web applications or websites, so that your trafficked size is smaller and therefore your application load time as well.

To do this, we will use the Apache web server configuration file, the .htaccess. Remember that files such as videos, music, and other binary files are probably already compressed, and because they are usually much larger than text files, would require a lot of server processing to compress them again, and the gain from compression would be Minimum.

For this reason, it is recommended to enable compression only on text files, and especially on “Big 3” (HTML, CSS and Javascript).

Enabling compression with DEFLATE

This is the easiest compression to configure on the server and is already enabled by default. It uses less server processing than GZip, but does not compress as much as it does.

Enabling Compression with GZip

GZip has been gaining a lot of space on the web today because of its great data compression power, reducing page load times dramatically, especially when we talk about mobile internet (3G) in Brazil, which is still very slow and precarious Many places. Because it has a high level of compression, it requires more processing than the DEFLATE compression method.