Gzip Your Website

How To GZIP Your Website By Adding The Code In .htaccess File?

how to gzip your website

In the field of blogging, people are trying hard to speed up their website. There are many things to do from which I am going to tell you about the compression technique. You can compress all the .txt and HTML files of your website using GZIP compression. It’s also a file format.

You can improve the speed of your website using GZIP compression. Do you know how to GZIP your website? There is nothing to worry about. I am here to let you know. In this post, I will guide you compressing the HTML files so that the page-speed can be improved.

How Can You Improve The Speed of Your Website?

First of all, you should know about the GZIP compression and what happens after that. When a web browser sends a request to fetch the files from the web server then the server checks the files and send them to the web browser.

What would happen if the size of the file is big? Your user will get frustrated and leave your website. It is because the loading time of the big file will more and no one wants to wait for a long time to see the content of your website.

What would happen if you GZIP your website? When the web browser would send a request to fetch the file then the web server will send a small part of the GZIP file to know that the web browser can accept a compressed file.

After that, the web browser would respond in a positive way and finally, the GZIP file would be sent to the web browser by the web server. The file is in the compressed form so the browser won’t take much time to show the content to your readers. The speed of the page of your website would be improved.

What To Compress Using GZIP Your Website?

We have talked about improving the page-speed and the working. Now is the time to know how can you GZIP your website. There is nothing much to understand about it. You just have to include a code in your .htaccess file. If you don’t find the file then you can create the .htaccess file and then add the code.

Before going further, let me tell you that GZIP code is different for different servers. For an Apache server, you can get the code which can work perfectly.

There are many web hostings which provide GZIP enabled for your website’s .txt and HTML files. But all of the web hosting companies don’t provide it. You should do it your own.

There are two types of compression for your website files:-

  • mod_deflate
  • mod_gzip

You can do it either way you want. But most of the developers recommend with the mod_gzip way. I will show you the code for both of the types. You can check which would work fine for your website.

Just GZIP your website by adding the code mentioned below in your .htaccess file.

<ifModule mod_gzip.c>

mod_gzip_on Yes

mod_gzip_dechunk Yes

mod_gzip_item_include file .(html?|txt|css|js|php|pl)$

mod_gzip_item_include handler ^cgi-script$

mod_gzip_item_include mime ^text/.*

mod_gzip_item_include mime ^application/x-javascript.*

mod_gzip_item_exclude mime ^image/.*

mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

</ifModule>

You can check the result with any GZIP checking tool.

I have shown the details of my website above. You can see that the compression is done by 74.5%. The size of the file has reduced.

Now can check the speed of your website at GTmetrix or Pingdom. If you see the results in your favor then congrats, you have successfully done your job. You motive to improve the speed of your website has fulfilled.

But if you don’t see any change in the speed of your website then you can deflate it with another code.

The process would be the same as you done above. Just open your .htaccess file and paste the code shown below.

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript

Did You Improve The Speed Of Your Website?

By using one of the codes from the two, you can GZIP your website. You should try the second code if the first code doesn’t work for your website. I am sure the page loading time will reduce and you will never ask how to GZIP your website again. You know that the page loading time of your website matters a lot. Google show the website on the front page which has better speed.

The point is that .txt and HTML file may be of the bigger size which isn’t easy to fetch for the web browser. So to reduce the size of these files you should GZIP your website. It will improve the speed of your website.

You can also connect with us on Twitter, LinkedIn, and Facebook.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.


Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE



Leave a Reply

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