This is Our Old blog with useful tutorials, We'll start posting tutorial In forum soon, please use this forum as blog is discontinued but will not been taken down Link to Forum
CentosControl PanelCWPLinuxWordpress

How to enable GZIP compression on Linux Server running Apache

GZIP compression is bundling (zipping) pages on a web server before the page is sent to the visitor.
This saves bandwidth and therefore increases the loading speed of the page significantly.
The visitors’ web browser then automatically unzips the pages. This compressing and unzipping only takes a fraction of a second.


GZIP compression is recommended for all types of text files such as:

  • HTML (.html) but also all types of dynamic HTML (such as extension .php, .aspx)
  • Textfiles (extension .txt)
  • CSS and Javascript (extension .css and .js)
  • Webservices, such as WSDL, REST and JSON

GZIP compression is not recommended for non-text files, such as graphical files and .zip files because it hardly saves space and can therefore increase the loading time.

GZIP compression saves 50% to 80% bandwidth and will therefore significantly increase the website’s loading speed.
The textfiles are compressed (zipped) on the web server after which the visitor’s web browser will automatically unzip the files. This compressing and unzipping only takes a fraction of a second without the end user noticing.

To¬† enable GZIP compression you only need to enable “Apache Module mod_deflate” you can search how to enable it on your distro.

How to enabled GZIP :

I assume you already activate mod_deflate module under Apache now you just need to put this line in .htaccess :

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent

this also will work on CWP, Cpanel etc.

Congratulation you just enabled GZIP compression on your site.

How to check gzip is working or not?

A. Visit this site , enter your site url then hit the check button, if you’ve successfully enabled GZIP compression then the result will be the similar as posted in below screen shot :

Sandeep B.

I'm a system admin and php developer and currently working as System Admin In CWP Control panel, expertise in Linux and Windows administration RHEL certified admin.

Related Articles


    1. if you’ve vps/dedicated server you can specify/add this line to your apache vhost :

      DeflateCompressionLevel 5
      compression value : 1-9
      where 1 is low compression and 9 is highest possible compression (highest will use more cpu) and 5 or 6 is the safest value

Back to top button