This post was last updated on January 2, 2024.
Enabling Gzip compression (also sometimes called HTTP or browser compression) is one of the most effective ways to make your WordPress site load faster. That’s good news because page loading time influences bounce rate, user experience, search ranking, and much more.
If you work with a computer regularly, you probably already know about compression from zip archives. They allow you to shrink files, e.g. to send them more easily via email. The same is possible for the files that make up your WordPress website, so that visitors can download them faster and see your site more quickly.
Not only does this provide a better experience for visitors and make you site more attractive to search engines, it also results in less server load and bandwidth usage. Good news for those with performance-based hosting packages.
Reason enough to look at this topic in detail, don’t you think? For that reason, in this article, we will go over several ways to enable Gzip compression in WordPress so that your site can be as fast as it deserves to be.
How Does Gzip Compression Work?
Before learning how to add compression to your WordPress website, let’s have a quick look at how this site improvement actually works.
Your Website Is Made Up of Files
As you probably know, most modern websites consist of a mix of HTML, CSS, and JavaScript, which — on the very basic level — are nothing but text files.
When a visitor requests to see your site, their browser downloads these files and renders the web pages from the code contained within.
So far, so good.
However, because the code is usually created and read by humans, it is usually arranged in a way that makes it easy to read for human eyes. To that end, it contains comments, line breaks, indents, spaces, and other code formatting.
function twentynineteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Footer', 'twentynineteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
Machines, like your browser, however, don’t need code to be pretty to be legible. As long as they can parse it, the markup can be in one block or a single line for all they care.
That’s the reason why a good way to make website’s load faster is code minification. This means nothing else than taking away all the formatting that is purely there to make code easier to consume for people.
As you can imagine, this saves a lot of space, which, in turn, makes the files smaller. Smaller files are faster to download, which means they arrive more quickly in your visitors’ browsers, so they can see your website earlier.
Compression Reduces File Size
Compression is one step further than minification. In order to understand how it works, you have to be aware that all code is at least somewhat repetitive. It’s simply in the nature of programming and web design to have lots of recurring patterns and elements.
Compression algorithms like Gzip take advantage of this fact by replacing repetitive patterns with a sort of shorthand. To make this clearer, let’s pretend we have a piece of code that looks like this:
AAA BBBB CCCCC
With a simple system we can reduce the same snippet to this:
3A 4B 5C
Easy to understand, right? We just shortened the recurring characters by showing how often they appear with the help of numbers. It’s simple, and if you know the system, you can easily reprocess this back into its original form.
However, what’s also remarkable is that this small step reduced the code example from twelve characters to merely six. That’s a reduction of 50 percent!
While that’s not actually how Gzip works, the idea behind it is very similar if much more complex. On the very basic level, Gzip is nothing but a library for compressing and decompressing data and it works especially well for text-based content like lines of code. In fact, the algorithm can reduce the size of HTML, CSS, and JavaScript files by as much as 70 to 90 percent.
(Note: It doesn’t work well for images. There are other ways to optimize them.)
Since all modern browsers not only support Gzip but will actually request it automatically, this makes compression a fool-proof method to speed up your WordPress website.
Benefits of Using Gzip Compression
One of the questions that might pop into your mind is, “why use Gzip compression?”. Not in terms of why use compression at all but why this particular one? After all, there are other compression algorithms out there, why not use those? Well, Gzip has a number of things going for itself:
- Decent compression rate — While other algorithms can shrink files to smaller sizes, Gzip’s rate of 70 to 90 percent is already very good and close to the maximum of what is possible.
- Fast compression and decompression — Where Gzip outshines its competition is the speed at which it can compress and decompress files. That makes it especially suited for ad-hoc applications such as websites.
- Low memory requirements — The compression method doesn’t need a lot of resources to do its work, therefore, it’s suitable even for low-end web servers.
- Open source — The G in Gzip stands for GNU. That means, it’s open source software like WordPress and therefore free to use and doesn’t need a license.
- Universal support — Gzip is one of the most widely used web technologies out there and supported by almost all servers and browsers. For other types of compression, such as Brotli, you need a server that specifically supports them.
In short, Gzip offers a great mix of features and benefits that makes it the go-to solution for website compression.
How to Test Your WordPress Site for Gzip
Before getting to the part where we talk about how to add Gzip compression to your WordPress site, let’s first go over how to test if your website already uses it. A lot of hosting providers offer compression by default, so you don’t want to try to add something you already have.
One of the easiest ways is to use a Gzip testing tool. Simply enter your website URL, hit the button, and it will tell you if your site is already compressed or not.
When you audit your website performance with speed testing tools, they will also tell you if you have compression enabled or not. For example, in PageSpeed Insights, you will either receive a warning to enable text compression under Opportunities or see it in the Passed Audits section.
GTmetrix will give you similar warnings.
Finally, you can also get this information from your browser. Open up your site in your browser developer tools, go to the Network tab, and reload the page to gather the necessary information. Then, click on any of the files the developer tools list here and look for content-encoding: gzip
under Response Headers.
This will show you whether Gzip has been used to download that resource. Make sure to select one that comes from your own URL and not an external service like Google Fonts.
No Gzip active on your site yet? Then let’s talk about how to change that.
How to Enable Gzip Compression on WordPress Websites
The first thing you need to understand about Gzip compression in WordPress is that the platform does not handle compression itself. Instead, it’s something that happens on the server. Therefore, you typically set up this feature by adding code to a configuration file and you have the following options to do so.
1. Have Your Host Set It Up
Don’t want to mess with server files yourself? Then why not ask the people who own the server to do it for you?
If you work with a quality hosting provider, they might offer setting up Gzip compression as part of their standard service. So, if you feel uncomfortable dealing with this topic by yourself, it may be a good idea to give them a call or chat.
That way, you can lean back and have experts set up this site improvement.
2. Use a WordPress Plugin
WordPress wouldn’t be WordPress if there wasn’t some sort of plugin solution out there to set up Gzip compression. In fact, it’s usually a standard feature in any caching plugin.
W3 Total Cache
In W3 Total Cache, you can find a check box to add HTTP compression to your WordPress website under Performance > Browser Cache.
Make sure it is checked and, if you make any changes, don’t forget to save them!
WP Super Cache
Another plugin option is WP Super Cache. If you have it on your site, you can find an option to Compress pages so they’re served more quickly to visitors under Settings > WP Super Cache > Advanced.
Check it, save, and you have Gzip enabled on your WordPress site.
WP Fastest Cache
Users of WP Fastest Cache find the option to switch on compression right on the first page of the plugin’s settings menu.
WP-Optimize
The WP-Optimize plugin also makes Gzip compression possible on your site. You find the setting under WP-Optimize > Cache > Gzip compression.
Simply click the big button that says Enable and the plugin does all the rest by itself.
As you can see, there are plenty of solutions to choose from. But they are not the only ones.
3. Enable Gzip Compression via .htaccess
If you don’t want to go the plugin route, you can also set up compression directly on your server by hand. This avoids potential plugin conflicts and keeps you from installing any other functionality on your site when all you want is text compression.
So, how do you do it?
If your site is running on an Apache servers, you’ll enable compression via a file called .htaccess
(yes, including the dot). It normally contains other important server instructions. For example, WordPress adds rewrite rules to .htaccess
to enable different permalink structures.
Other things this file can do are redirects, protecting files and folders from access, and much more. Here’s how to use it to enable Gzip compression.
Find And Edit .htaccess
To make any changes to your file, you first need to find it. That’s not always easy, because it is hidden by default. The easiest way to access .htaccess
is via FTP but you can also use cPanel or any other admin interface.
In this case, we will start by opening our FTP client of choice and connecting it to the server. .htaccess
is usually located in the root directory of your website’s folder. However, as mentioned, it is most often invisible.
In FileZilla, you can change that under Server > Force showing hidden files. Your software might have the option somewhere else.
After you have located it, you can edit the file like any other. In FileZilla this means right-click and then View/Edit.
Alternatively, you may also download .htaccess
to your computer and make changes on your hard drive. In fact, you should probably do that anyway in order to have a backup in place (safety first!).
If you go the download route, be aware that your operating system might also hide the file and you won’t see it unless you change your display options.
In Windows, these are located in the Folder Options. In that menu, find the View panel and then enable Show hidden files, folders, and drives.
If you are using MacOS, simply press Cmd+Shift+. (the dot) to make invisible files visible so you can edit them.
Add the Necessary Code
Overall, enabling Gzip compression is not that challenging. All it takes is adding the following piece of code to the .htaccess
file (code credit goes to GTmetrix):
<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
# Remove browser bugs (only needed for really old 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>
Place it somewhere outside the # BEGIN WordPress
and # END WordPress
brackets.
While it will work either way, if you put the code inside the brackets, there is a chance WordPress will overwrite them.
In case you have problems with the code above, you can also use the alternative 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
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
AddType text/css .css
That’s pretty much all it takes. Save and upload your file and Gzip should be ready. However, in order to be sure, let’s verify it is actually doing its job.
Verify Gzip Compression Is Working
Once you have set up compression on your WordPress site, the last step is to test if it actually works. We’ve already covered how to do that, so you can use the tools mentioned above for that purpose.
If you don’t see a change right away, that doesn’t necessarily mean you made a mistake. It might just take some time for the compression to take effect (especially with larger sites) or for the site cache to update. In that case, simply try again a little later.
If everything works, congratulations! You just took a big step in speeding up your WordPress website.
4. Using Gzip Compression on NGINX Servers
As mentioned, .htaccess
is the configuration file for Apache servers. If your site is on an NGINX server, you need to edit a file called nginx.conf
instead and also add this code snippet to it:
gzip on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;
gzip_vary on;
You can find more information in the NGINX documentation. Aside from that, everything else stays the same.
5. Compress Your WordPress Site on an IIS Server
If you are running your website on a Microsoft IIS server, please refer to their documentation for how to switch on Gzip compression for your server version.
Additional Considerations to Keep in Mind
Be aware that your website likely consists of more than what is located on your own server. Most modern websites use at least some external assets, such as custom fonts, jQuery, or web analytics. You might also be using a Content Delivery Network (CDN) to provide some files to your visitors.
To have your site load as fast as possible (and avoid getting a warning that it lacks Gzip compression), make sure that these assets are also compressed. You can check this with the same tools mentioned above, by inputting the URL where your external assets are located.
That way, your WordPress site is not a mixed bag when it comes to compression. By the way, here are a few additional ways to speed up your WordPress website:
- Speed testing your website — To find out where the bottlenecks lie.
- Reducing server requests — What’s faster than downloading files that have been compressed? Not having to download them in the first place!
- WordPress speed optimization without plugins — Because you don’t need plugins to have a blazingly fast website.
- Speed Up the WordPress Back End — Because it’s not just about your website’s front end.
- Core Web Vitals — Learn how to improve Largest Contentful Paint, First Input Delay, and Cumulative Layout Shift.
Final Thoughts: Gzip Compression for WordPress
Never underestimate how much site speed can affect your site’s popularity among visitors and search engines. How fast your pages load is a sign of quality and smart website owners do their best to make their WordPress websites as fast as possible.
Gzip compression is a simple but effective tool that can make a huge difference in this area. It is also easy to implement so there is no excuse not to take advantage of it. Hopefully, this guide helped you do just that. Now it’s time to move on to all the other ways you can improve your site’s performance.
Have you enabled Gzip for your website? How did you do it? Any thoughts or additional tips? Please tell us about it in the comment section!
98 Comments