mod_deflate is a very useful Apache module that allows your server to compress data with gzip compression, before sending response to client. It helps you save a lot of bandwidth and data costs. However, it may consume more resources on server, as it needs to compress each file on server. Let us look at how mod_deflate works
How mod_deflate works
mod_deflate module allows Apache server to compress each file and data using gzip compression, before it is sent to the client browsers. Modern browsers automatically uncompress the data received from your server and render the uncompressed data to the users.
All this happens very fast behind the scenes, and the users can’t notice the difference in page load speed. However, it saves a lot of bandwidth for your server as all the response data is compressed before it is sent.
On the other hand, mod_deflate is resource intensive, as it needs to compress all files on your server. So it is not advisable to use mod_deflate on old servers.
In fact, on modern servers, you can use other solutions like caching to save network bandwidth. Here’s how to enable caching in Apache.
How to Install mod_deflate on Apache
By default, mod_deflate is already installed on Apache, when you install the server
How to use mod_deflate
You can use mod_deflate in 2 ways:
- via cPanel
- via .htaccess
Enabling mod_deflate via cPanel
1. Go to your cPanel Admin. Under Software/Services, click Website Optimization
2. If you want to compress everything, select Compress all content. Otherwise, select Compress the specified MIME types and select the specific MIME types you want to compress
3. Click Update Settings to save changes
4. To turn off GZip compression, select Disabled in Website Optimization page and click Update Settings
Enabling mod_deflate via .htaccess
Before you proceed, please ensure .htaccess (mod_rewrite) is enabled on your Apache server. Here’s how you can do it:
Here are the steps to enable mod_deflate via .htaccess
1. Open .htaccess file in text editor
2. Add the following line
3. Save and close the file
4. Restart Apache to apply changes
$ sudo service apache2 restart
$ sudo systemctl restart httpd
How to test if mod_deflate is working
You can use online third-party tools to check if mod_deflate is enabled on your website or not.
That’s it! Now you know how mod_deflate works.