blog posts

Training on how to fix the Enable gzip compression error in GTmetrix

Now that you are reading this content, you must have experience using ZIP format files in different operating systems such as Windows, Linux, Android, and IOS. You had Or has it happened to you that when you download a movie, program, music album, and anything from different sites, most of the time, the files are in zip format? Have you ever wondered why this format is so common on download sites? The reason for doing this is to reduce the size of the file because when you zip a file, it is compressed, and the size of the file is significantly reduced. This work has an advantage for the site in question as it occupies a smaller amount of server and host and it will take less traffic for the user who is downloading files. The use of Gzip on the site is for the same reason: it reduces the size of files and increases the site’s speed. In this tutorial, I want to teach how to fix the Enable gzip compression error in GTmetrix.

In this tutorial, the Hostfa knowledge base, I will first discuss what Gzip is and whether it is necessary to use it

What is Gzip? And what is its use?

You must be familiar with the zip and rar compression formats you use to reduce the size of your files. Gzip has the same function as this software and formats, which is used to reduce the size of website pages using the algorithm used by this compression method, which we know as gzip. Today, all browsers support this feature. When you enter a site, the browser first sends a request to determine whether gzip is enabled on this server or not. If the answer to this request is positive and it is clear from the server side that the browser supports this feature, the server will start sending files in a compressed format to the browser. But if the answer is negative, the files will be sent with normal size, which is not compressed, and because of the high volume of the files, the speed of your site will be low.

When a user enters your site, a request to receive site information is sent to the server in the browser, and after the server gives a positive response to this request, the files start to load. Now, the larger the size of these files used in the pages, the more time will be spent on loading the site. Therefore, we should reduce the size of our pages using gzip so that a web page is loaded and available for the user in a shorter period of time. Using gzip, all files related to html, css and javascript are compressed and their duplicate codes are ignored, which will ultimately lead to an increase in site speed.

In the files that are related to programming, the codes will be converted into shorter and more concise characters using page size compression technology. For example, if your file contains a text containing the words MM I ZZZZZ BB A nnn f AAA , which contains 25 characters, it will be converted into abbreviated form and 3M I 5Z 2B A 3n f 3A sent to the browser It will be summarized up to 5 characters (including spaces). Then the browser that supports Gzip will understand this and process the codes in standard mode and finally display the structure of a site correctly.

Gzip analysis and verification

Before I go into the methods of using gzip, I suggest that in order to really see how much gzip will be effective in increasing the speed of the WordPress site, once analyze and check your site that does not use gzip. For this purpose, checkgzipcompression.com and then, similar to what you see in the image below, enter the full address of your site in the corresponding field, click on the search icon, and wait until the site is analyzed and based on WordPress plugins and templates. which you use will tell you how much you can reduce the size of your pages using Gzip.

Fixing the Enable gzip compression error in GTmetrix and enabling gzip

Since Gzip is enabled on Hostfa’s servers , in the test I did, 28.1% of my pages will be reduced in total. But on a host where gzip is not active, you can reduce the size of pages by 70%.

Another method of checking is using the browser itself, which you can see by right-clicking on the site page and selecting the Inspect Element option to see the source of the pages. Then, similar to the image below, click on the Network tab and now refresh the site once without closing the Inspect Element window. If you see content-incoding: gzip, it indicates that Gzip is active on the site.

Fixing the Enable gzip compression error in GTmetrix and enabling gzip

From this section, you can view and compare the amount of file compression before and after. For this, it is enough to click on the row view and see the compression amount for each file from the Size column.

Fixing the Enable gzip compression error in GTmetrix and enabling gzip

Fixed the Enable gzip compression error in GTmetrix

To fix the Enable gzip compression error in GT Matrix, it is enough to activate the Gzip function on the site, which I will continue to introduce the methods of activating gzip on different sites and web servers.

Enable Gzip in WordPress

For this purpose, you can activate Gzip on the WordPress site both by using the plugin and by coding. There are different ways to activate in WordPress, in the coding method, you have to put the codes in the htaccess file. put For this purpose, you can use the tutorial article on how to activate gzip in WordPress .

Enable Gzip on Apache server

For this purpose, depending on the control panel of the host admin that you use, you must first enter the File Manager of your host.

Fixing the Enable gzip compression error in GTmetrix and enabling gzip

Similar to the image above, by clicking on the File Manager option in the cPanel host, you will enter the file management environment in the host, now enter the path where you installed WordPress on the site. If WordPress is installed on your domain, just go to / public_html/ and look for a file named htaccess. look around But if you try to install WordPress in a subdomain or subfolder, it is enough to refer to the desired path where WordPress is installed in that folder and look for the htaccess file. look around

htaccess file. It is one of the hidden files in the host that you may not be able to see when you first log in to the host. So, click on the Settings button on the top right side of the screen to open the following window. Then select the Show Hidden Files option and finally click on the Save button to save the settings.

Fixing the Enable gzip compression error in GTmetrix and enabling gzip

Now able to view the htaccess file. and you can edit this file by right-clicking and selecting the Edit option and add the following codes in the right place of the file. I suggest you put the following codes at the end of this file so that there is no interference with other codes.

<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

# Removing browser bugs for older 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> 

Enable Gzip in Joomla

To enable gzip in Joomla, after entering the Joomla management section, go to the general settings and enable the Gzip compression option in the server tab and save the settings