Enabling Gzip Compression (mod_deflate)

For Linux Web Hosting packages

In this article, we'll show you how to activate the Apache web server compression module mod_deflate through the .htaccess file. (The article about compressing PHP scripts via zlib can be found here)

Activating mod_deflate will enable the compression of HTML and CSS files through gzip. This reduces the amount of data transferred by up to 70%, resulting in shorter, faster load times for your website.

Especially for visitors with relatively slow connections - for example via smartphone - compression can bring a noticeably better performance.

Enabling GZIP Compression:

Step 1

Connect to your webspace through SFTP and download the .htaccess file to your PC.

Please Note: If no .htaccess file exists yet, you must recreate it in the next step.

Step 2

Open the .htaccess file with a text editor such as Notepad++. Insert the following code at the end.

Tip: If required, you can restrict compression to specific MIME types.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/shtml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule> 
Step 3

Save the .htaccess file and upload it back to your webspace.

Note: The changes to the .htaccess file apply to the storage directory and its subdirectories. This means that if the .htaccess is in the root directory, the GZIP compression is activated for the entire webspace.

Testing GZIP Compression:

  • The Website-Checker helps you to optimise your website and also gives you information about whether GZIP compression is actually active.
  • Google PageSpeed Insights is a tool provided by Google that checks the loading speed of websites and gives tips for optimisation.
  • Alternatively, you can use your browser's developer tools. Open your website in the browser, activate the developer tools, and select Network (Analysis). In the network area, select the Headers tab and search for the line Content-Encoding: gzip in the reply headers.

Please note: Most content delivery networks such as CDN already use effective compression. Therefore, you do not need to enable gzip compression when using CDN.