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.

HOW TO ENABLE BROTLI COMPRESSION IN NGINX, CWP, VESTACP AND ON LINUX OS

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/vnd.ms-fontobject
  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
</IfModule>

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 https://www.giftofspeed.com/gzip-test/ , 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 :

Back to top button