Compression is an extremely common concept. If you’ve spent any time working with computers, you’re probably already familiar with it. For those who are unfamiliar: compression is a very useful tool for combining many files into one significantly smaller (and more readily transportable) file, which translates to faster page load times for websites.
In this post, I’ll look at how gzip compression works and how you can enable it on your own WordPress-powered website.
How Compression Works
Let’s begin by looking at what compression is and how it might help.
The strategies used by data compression algorithms such as gzip employ patterns and repetitions found in the text to create a more efficient way of storing information. Consider the following scenario.
Here’s some HTML code to make the text within it display in bold:
<strong>this is bold</strong>
This is, in fact, a fairly lengthy phrase.:
eNqzKS4pys9LtyvJyCxWAKKk/JwUG32oIC8XALn8Cuo=. However, compare the following with what happens when we compress it:
<strong>this is bold</strong> <strong>this is bold too</strong>
The compressed version is
eNqzKS4pys9LtyvJyCxWAKKk/JwUG32oIC+XDRZphZL8fCQlACNDF0U=. Despite the fact that the original text is more than twice as long, the compressed version is only 16 characters longer — a 32% reduction in size, which means less to load and faster website loading.
How to Enable GZIP Compression to Speed Up WordPress Sites?
It’s vital to note that WordPress isn’t in control of gzip compression. It’s actually handled by the servers themselves (rather than within WordPress), so you’ll need to set it up outside of WordPress to enable it.
ASK YOUR HOST:
The first and most important thing to keep in mind is that you must modify (or even create) a file that is not necessarily the simplest to deal with (known as an “htaccess file” ), so if you’re not sure what to do, ask your host to handle it for you.
SETTING THINGS UP ON YOUR OWN
A hidden file, named .htaccess, is used to give a server special directions like redirection or automatically adding files to specific requests, among other things—and it’s even capable of enabling gzip compression! Finding and then editing this difficult file may be the tricky part.
The first thing you’ll need is access to the files on your server. For most people, the easiest way to get access is using FTP. However, because a site’s htaccess file is a “dot-file” (meaning it’s typically hidden), finding it may be more difficult than usual.
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_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
Check gzipped compression by GTMetrix
There are several ways to check whether or not a site’s files are gzipped compressed, with one of the simplest (and most fascinating) being via the excellent GTMetrix site testing tool – something we’ve already discussed in an earlier post: How to Use GTMetrix to Test a Website’s Speed Effectively!
After that, you should notice the in your GTMetrix results under the “Waterfall” category.
Gzip compression, like most things related to web performance, is one of those easy yet effective ways (or tasks) to improve (or add) your site’s speed without having to make any changes in code. If you don’t enable it, you’ll be losing out on a significant speed boost.
Finally, if you’re interested in learning more about a website’s htaccess file, I’d recommend reading Tuts+’s excellent htaccess guide, which has a lot more information and a few useful nuggets that you might use to your site’s advantage.