> Blogging > Optimizing Gzip for your WordPress installation

Optimizing Gzip for your WordPress installation

June 5th, 2019

Have you ever read about Gzip compression? It is a wonderful way to speed up your WordPress site. What Gzip does is to compress your website information on the server before sending it to the Internet. That way, your visitors receive less information than what they would usually get if your site was not compressed. The reduction can be between 60 and 90 percent in many cases, and Gzipping a site is considered a standard practice for optimizing a website and is highly recommended by experienced web developer such as WordPressintegration.

What happens is really easy to understand. Originally, when your server receives a request from a viewer that, for example, wants to read your home page, the server sends in all the information your home page contains, including the HTML, the CSS files, the Javascript files and the images just as a copy. That is, if your home page is 1 MB large, the server sends 1 MB of information. When you compress a website with Gzip, what the server does is to have a short conversation with your visitor’s browser. It’s something like this:

Browser: “Hello, I request to see the home page of the site, please”.
Server: “OK, I found the home page information. Does your browser accept Gzipped content?”
Browser: “Yes, it does.”
Server: “Ok, then let me compress the information for you… Ready… I’m sending in the compressed information now.”
Browser: “Receiving… Thank you.”

When the server compresses the information, the size of what it sends reduces, for example, from 1 MB to just 384 KB, saving you bandwidth, and to the viewer, downloading speed. It is always faster to download 384 KB than 1 MB of information, after all. Needless to say, the visitor’s browser uncompresses the information on the fly to show the requested home page in the visitor’s screen, so no information is lost in the process.

Although Gzipping content is considered a standard practice online, there are still millions of sites in which either Gzip has not been implemented, or in which it is implemented just partially. In this article, I want to give you a couple of tips to help your WordPress installation be completely Gzipped so you can reap the benefits.

How to Gzip your WordPress site

The easy way to Gzip your WordPress site is by adding a plug-in to your WordPress installation. WP Super Cache is, by far, among the most popular WordPress plug-ins that help you enable Gzip compression. The downside of using a plug-in, however, is that they usually Gzip compress your website partially, so, let me tell you something: If you are OK with a partial compression, or if you would prefer not to get your hands dirty manipulating some code because you don’t feel comfortable enough to do it, then it is OK. Download the plug-in and enable the compression. It will help you a lot anyway, and a partial compression is always better than no compression.

The not-so-easy way is not that hard either, but it requires some coding. Let’s get into the details.

When I say that popular WordPress plug-ins compress a site partially, it is because they compress the resulting HTML page, but not its parts, like, for example, the CSS or the Javascript files. To compress everything in your WordPress installation, you should enable compression by using a file named .htaccess. The .htaccess is a Linux/Unix file with instructions that works at the server level, and which allows webmasters to provide some site-wide or folder-wide instructions to control the server behavior.

What you will need to do first is to log in to your server with your favorite FTP client. Look for the .htaccess file and download a copy to your computer. My advice is to make a backup copy before editing it. Ready? Then open the .htaccess file with your favorite text editor. Any will do. It is just a text file, after all.

Now add the following lines to your .htaccess file.
<IfModule mod_deflate.c>
<FilesMatch “\.(htm|js|css|xml|php)$”>
SetOutputFilter DEFLATE

On the FilesMatch line add the extensions of files you wish to compress. In the example above, I am compressing all HTML, Javascript, CSS, XML and PHP files, which should be enough for most WordPress users. If your site is using a custom font via @font-face, you may want to add your SVG, TTF or WOFF files to the list too, but it’s up to you.

What you should NOT try to compress are files what are already pre-compressed, such as image files. A different procedure is done to compress images and optimize them, but that goes beyond the scope of this article.

Once your new .htaccess file is ready, upload it to your server replacing the previous .htaccess file that was there, and test your site. The results are, fortunately immediate. If your changes were successful you may notice a slight increase of the speed of your site. If it doesn’t work, you will get a 500 error message. If this happens, replace the .htaccess file with your backup copy. It means that mod_deflate is not enabled on your site, and you will need to ask your hosting company what modules are installed for your account, and how you can enable Gzip compression on your site.

Anyway, almost every hosting service in the world allows Gzip compression, so you shouldn’t have problems.

Author Bio:This Post Written By Jorge Aguayo(@tedel). He works in Search Engine Optimization team of InTechCenter web design and software development company now, although his experience in the field started back in 2007.

Certifications &