Mod_deflate is essential nowadays for websites – it speeds up the transfer of HTML pages and other files (such as stylesheets) by compressing them first. With today’s powerful servers, there is very little reason not to use this functionality, especially since many “speed up” tests will not pass without it being enabled.

While you can enable mod_deflate site-by-site, for shared hosts with many websites this approach is inefficient. Fortunately, you can enable it globally for all sites on your server.

Step-by-Step Implementation

1. Ensure mod_deflate is Installed

First, make sure the module is installed on your server:

  • Use EasyApache and verify that mod_deflate is selected (it may already be)
  • Once Apache has been compiled, deflate functionality will be enabled

2. Site-by-Site Option

If you want to enable the functionality site-by-site:

  • In each site’s control panel, a new option is now available
  • Under Software/Services, users can choose to optimize their website
  • This essentially allows deflate to be turned on and off per site

3. Global Implementation (Recommended)

To enable mod_deflate for all websites on your server:

  1. In WHM, navigate to: Services Configuration → Apache Configuration → Include Editor → Post Virtual Include
  2. Select All Versions (there’s no reason not to apply it to all Apache versions)
  3. Paste the following code into the file and click Update:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
# Don't compress images as it's generally pointless
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
</IfModule>
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
#maximum compression - why not, we have spare CPU
DeflateCompressionLevel 9
</IfModule>

Benefits of Global mod_deflate Implementation

Enabling mod_deflate across your entire server provides several advantages:

  1. Reduced Bandwidth Usage: Compressed files are significantly smaller, reducing overall bandwidth consumption
  2. Faster Page Loading: Smaller file sizes mean quicker transfers and faster loading times for visitors
  3. Improved User Experience: Faster websites mean happier users and higher engagement
  4. Better SEO Performance: Page speed is a ranking factor for search engines
  5. Consistent Configuration: No need to remember to enable it for each new site
  6. Minimal Server Impact: Modern CPUs can handle the compression with negligible performance impact

Technical Details

The configuration above sets the compression level to 9 (maximum), which provides the highest level of compression. While this requires slightly more CPU resources, modern servers generally have plenty of processing power to spare, making the trade-off worthwhile.

The configuration also excludes image files (GIF, JPEG, PNG) from compression since these formats are already compressed, and attempting to compress them further would waste CPU resources with little to no benefit.

The “Vary” header is included to ensure proper handling by proxies and caches, preventing them from serving compressed content to clients that can’t handle it.

By implementing this server-wide setting, you’ll ensure all websites hosted on your server benefit from compression without requiring individual configuration.