How to enable GZIP compression on Apache web server
Last updated: Aug 17, 2022
Colleagues hello to all.
In today's article, we'll talk about how to enable compression on a site in the Apache web server and talk about why to do it.
The compression process is a good solution for optimizing your site by saving your traffic and loading the site much faster in the user's browser. Plus, you will have an important advantage over other sites that do not have compression enabled, this is that search engines rank pages with compressed text better, and thus the position of your site will be higher than that of those who do not have compression enabled.
Compression in Apache is handled by two modules. The first module is called mod_deflate and the second is mod_gzip, you only need to enable one of them.
The mod_deflate module compresses data dynamically, meaning that data is compressed on the server side by Apache when it is in transit to the user's browser. An important plus of mod_deflate is that the size of the site page significantly reduces weight and download speed in the browser. In this module, there is only one small minus, which is that when sending the page to the user, there is an additional load on your server. But if your server is powerful enough, then you won't have any problems.
To enable the mod_deflate module, you need to find the .htaccess file in the root directory of your site and add a few lines of code to this file.
I won't show you how to enable the mod_gzip module because you you will not use. This module has one big disadvantage in that you need to compress each file yourself and upload it to the root directory of the site. After that, the server will transfer the data to the user's browser immediately in a compressed form.
And so after you have added the mod_deflate module, now you need to make sure that compression works for you. In order to check compression, we can use different online services.
I checked my site for compression and got the following data.
- Web page compressed? - Is page compression enabled.
- Compression type? - The type of compression that the page uses.
- Size, Markup (bytes) - How much the page weighs without compression.
- Size, Compressed (bytes) - The weight of the page after compression.
- Compression % - Page compression process.
As a result of the check, the service showed that my site uses gzip compression.
Thank you all, I hope that my article helped you in some way.