How to enable Gzip compression using the .htaccess file

It’s important to enable Gzip compression on your website to reduce the time it takes to transfer your webpages, images, and CCS.

First you will need to find out if Gzip compression is enabled on your server or not. You can do that by using this website gtmetrix.com.

website-speed

Simply enter your website url and hit “Analyze”

I have tested a website and as you can see gzip compression is not enabled.

issue-gzip-compression

This is also a tool you can use to find out if Gzip compression is enabled. Gzip compression tool

If you don’t have access to your server then you can simply add the following code to your .htaccess file which can be found inside your root folder.

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

Code source:giftofspeed.com

Here is an example

wrdpress-gzip-code

After posting the code, save your file then test your website speed again.

 

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *