Guide to Gzip Compression in WordPress
In this post, we’ll explain what Gzip compression is and why it matters. Then, we’ll show you two ways to implement it.
Keeping your website running at top speed is essential. It provides a huge boost to your users’ experience and improves your site’s professionalism and reliability. This means you need to find every way you can to make your pages load more quickly.
Gzip compression is one popular method you can use to speed up your site. While the term itself may sound technical, the basic concept isn’t too complicated. What’s more, enabling Gzip compression on your WordPress site is surprisingly easy.
An Introduction to Gzip Compression
As your site expands, many of its files grow in size as well. This is a natural result of adding more content, plugins, and themes, as well as custom code to your site. All of that new data has to be stored somewhere.
The downside of larger files is that they often take more time to load when your pages are accessed. This means your visitors will end up waiting longer to view your content – which is never a good thing. To deal with this problem, you need to find a way to make your site’s files smaller without losing any important information.
This is exactly what Gzip compression does. It reduces the size of your files by ‘compressing’ them, removing unnecessary characters and reorganizing data more efficiently. If you’ve ever ‘zipped’ a folder to make it smaller, this is a similar concept. Gzip compression can reduce the overall size of your pages by up to 70%, and nothing crucial is lost in the process.
How to Enable Gzip Compression on Your WordPress Site (2 Methods)
There are a lot of ways to speed up your WordPress site. For example, choosing an optimized hosting plan is key. Gzip compression can help to improve your page speeds even further, however, so it’s worth implementing.
Below, we’ll show you two ways to get started with Gzip compression. The first thing you’ll want to do is make sure you have a recent backup of your site in place, as a safety precaution. Then you can read through both methods, and choose the one you prefer.
1. Use a Plugin
You may struggle to find a quality plugin exclusively designed to implement Gzip compression. Fortunately, you don’t need one. Many speed optimization plugins include an option for Gzip compression as a part of their feature set. For a perfect example, check out WP Super Cache:
This plugin is primarily a caching solution, which is another smart way to speed up your WordPress site. However, it also enables you to compress your files. After installing and activating the plugin, you’ll want to navigate to Settings > WP Super Cache and switch over to the Advanced tab:
Find the option labeled Compress pages so they’re served more quickly to visitors, and check the box next to it. Then click on the Update Status button to save your changes. That’s all you need to do – the plugin will now implement Gzip compression automatically!
2. Modify Your .htaccess File
While the above technique is the simplest way of enabling Gzip compression on your WordPress site, some users will be more interested in an alternative method. If you’re trying to limit the number of plugins you install on your site, for example, you might prefer to implement Gzip compression manually.
To do this, you’ll need to use Secure File Transfer Protocol (SFTP). This enables you to directly access (and make changes to) your site’s files. If you’ve never used SFTP before, you’ll first want to install a suitable client, such as FileZilla (and brush up on your SFTP skills). Then you’ll need to establish a connection to your site using your hosting credentials.
Once you have FileZilla set up, it should look something like this:
In the top right quadrant, find the folder named after your website’s domain and select it. Then, in the bottom right quadrant, look for the file called .htaccess. This is one of your site’s core files, so you should always be very careful when making changes to it:
Right-click on the .htaccess file, and select Download to save it to your computer. Then open the file in any text editor (such as Notepad), and paste in the following code:
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/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/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 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
Don't forget to save your changes to the file. After that, you can re-upload it to your site by copying and pasting it back into your website's root folder (or simply dragging it there from your computer). With that, you’ve enabled Gzip compression on your WordPress website manually!
There are a lot of ways to make sure your WordPress site runs fast and efficiently. For example, you’ll want to choose an optimized hosting plan with a reputation for speed. After that, there are plenty of smaller tweaks you can make to maximize your site’s performance – such as by using Gzip compression to reduce file sizes.