How to enable GZIP compression

GZIP-Compression

Hello, friends, today’s topic is how to enable GZIP compression on your web server. If you know what GZIP is and how to enable it, that’s good. But if you don’t, please read this tutorial till the end.

What is GZIP Compression?

GZIP is a file format and software application used to compress and decompress website files. It works by compressing files like HTML, stylesheets, and JavaScript. Enabling GZIP compression is one of the easiest and most effective ways to optimize your website’s performance.

GZIP compression never work on images because these are compressed in a different way

How do we check whether GZIP Compression is enabled or not?

Don’t worry, this is not a complicated task; you can check this on your browser, and all browsers support this. We have to just check the content-encoding: gzip HTTP response header in the browser Devtool. If it is active, it means GZIP is enabled on your website. Let me show you in the screenshot.

Content-Encoding

According to the screenshot above, GZIP compression is enabled on the website.

How do we enable GZIP Compression?

  • From the server
  • Using the website’s .htaccess file

First, we will see how we enable mod_deflate from cPanel, check screenshots below step by step:

  1. First, log in to your cPanel account. Then, go to the Software section, and click on the Multi PHP INI Editor. See screenshot below:MultiPHP INI Editor
  2. Now, on the Multi PHP INI Editor page, select the domain where you want to enable deflate. See the screenshot below:Select your domain
  3. Zlib.output_compression, below, enable it, and click Apply.zlib output compression

Above, we saw how we enabled GZIP compression or the deflate, but what happens if this PHP Directive is not available in your cPanel? Ok, don’t worry, we will walk you through this. If we have WHM access, then below steps will help to enable GZIP Compression. If you don’t have WHM, then ask your hosting support.

Let’s see the WHM steps to enable GZIP Compression. Please follow the screenshots, they will help you more…

  1. Log in to your WHM, search EasyApache in the search bar, and click on EasyApache 4, see screenshot…
    search easyapache in WHM
  2. On the EasyApache 4 page, we have to customize cPanel. Click the Customize button of the cPanel Default box, see screenshot…customize cpanel
  3. Once you are on the cPanel Customize page, Apache Modules >> search deflate >> enable mod_deflate. Once you enable it, click the Review tab, follow the screenshot below…deflate in WHM
  4. After clicking Review tab >> scroll down, click Provision button >> wait till the process ends>> once Provision finishes successfully, hit the Done button to complete the process.
  5. mod_deflate is now enabled successfully.

Another way to enable GZIP Compression is by editing the website .htaccess file. You simply need to add the code to the .htaccess file, but make sure mod_deflate is enabled on the server, as explained earlier in this article.
You can find your .htaccess file in the website root directory through FTP(FileZilla).

  # 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

Please make sure to add this code below the existing contents of your website’s .htaccess file.

How did GZIP Compression work?

When a browser (Chrome, Firefox, etc.) visits a website, it first checks to see if the server has GZIP enabled by determining if the Content-encoding: gzip response header exists. If the browser detects the header, then the server sends compressed and smaller files. As a result, the website loads fast.

Therefore, friends, if you follow these steps, your website will definitely load faster. Also, please let me know through your comments if this article helps you.
Keep learning.


Discover more from Wordpress Tutorial for Beginner's

Subscribe to get the latest posts sent to your email.

Share:

Facebook
Twitter
Pinterest
LinkedIn

2 thoughts on “How to enable GZIP compression”

  1. Hey phpyouth ,

    Great post with effective tips to enable the Gzip compression.

    Gzip is a file format and software application used to compress and decompress the website file but it is also true that Gzip compression technique never works on images.

    Your suggested steps to enable the Gzip compression are clear, easy to understand and follow, whereas following these steps will be helpful and allows the users to enable the Gzip compression.

    Truly helpful post and thanks for sharing.

Please share your thought

Discover more from Wordpress Tutorial for Beginner's

Subscribe now to keep reading and get access to the full archive.

Continue reading