Are you worried about your website page speed and page loading time? Do you see a bad Google PageSpeed Insight score for your website? Then you may like to “Enable Gzip Compression in WordPress” in order to optimize your website speed.
In this article, you will learn how to enable Gzip Compression to make your site load faster. To get fast load times on your WordPress site, reducing the size of your pages is important.
Enabling GZIP compression can help reduce the size of your webpage, which can significantly decrease the amount of time to download the resource, reduce data usage, and improve the time to first render of your pages.
Gzip compression is one of the most effective ways to make your site load faster, which is also sometimes called HTTP or browser compression.
What is GZIP Compression?
GZIP is a file format, a software application used for file compression and decompression. GZIP compression is enabled at the server-side and allows for further reduction in the size of your HTML, CSS, and JavaScript files. Before the page is sent to the visitor, it saves bandwidth, therefore, increases the loading speed of the page improves significantly.
GZip Compression –
- Compress 100kB file to 10KB.
- Reduces Page sizes & Increase page speed.
You can test your speed, with tools like Google page speed insight and GTmetrix. In case you don’t have GZIP enabled, Following warning and error display:
- Enable compression warning in Google PageSpeed Insights.
- Enable GZIP compression warning in GTmetrix
How ZGip Compression Works
Before moving on to how to implement it, let’s first take a look at what compression means and how it can help.
Nowadays, almost all modern websites use a mixture of HTML, CSS, and JavaScript, written by programmers in a logical, globally understood way. The result of this is almost always quite a bit of overhead that serves nothing more than human readability. Furthermore, most programmers will also use various design patterns and common elements, thereby leading to a fair amount of repetition.
Compression algorithms such as gzip use the patterns and repetitions found within the text to create a more efficient way of storing data. Let’s look at an example.
Here’s some HTML code to make the text within it display in bold:
<strong>this is bold</strong>
The compressed version of this is actually pretty long:
eNqzKS4pys9LtyvJyCxWAKKk/JwUG32oIC8XALn8Cuo=
However, take a look at what happens when we compress the following:
<strong>this is bold</strong> <strong>this is bold too</strong>
The compressed version is:
eNqzKS4pys9LtyvJyCxWAKKk/JwUG32oIC+XDRZphZL8fCQlACNDF0U=
Even though the original text is more than double the size, the compressed version is actually only 16 characters more — a whopping 32% reduction in size, which means less to load and a faster website.
Enabling GZip Compression for WordPress
If you don’t have GZIP compression enabled, don’t get panic. Let’s have a look at a couple of ways you can go about enabling it on your web server. You, need to understand that compression is not handled by WordPress itself but, through a server configuration.
Enable Gzip Compression in WordPress via .htaccess
To enable Gzip Compression in WordPress via .htaccess, you need to Log into your cPanel and follow the following steps.
- Under file section, select file manager menu.
- Check the checkbox show hidden files and click Go.
- Under public_html folder of your website, find and edit the file called .htaccess.
- Paste the following code into the .htaccess file at the end of your existing content.
# BEGIN GZIP COMPRESSION <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> # END GZIP COMPRESSION
The instructions and code above will work on Apache. If they are not working there is another way that may work for you. If the above code did not seem to work, remove it from your .htaccess file and try this one instead.
- DEFLATE Compression – Copy and Paste the following code in WordPress .htaccess file of your website.
# BEGIN DEFLATE COMPRESSION <IfModule mod_filter.c> AddOutputFilterByType DEFLATE "application/atom+xml" \ "application/javascript" \ "application/json" \ "application/ld+json" \ "application/manifest+json" \ "application/rdf+xml" \ "application/rss+xml" \ "application/schema+json" \ "application/vnd.geo+json" \ "application/vnd.ms-fontobject" \ "application/x-font-ttf" \ "application/x-javascript" \ "application/x-web-app-manifest+json" \ "application/xhtml+xml" \ "application/xml" \ "font/eot" \ "font/opentype" \ "image/bmp" \ "image/svg+xml" \ "image/vnd.microsoft.icon" \ "image/x-icon" \ "text/cache-manifest" \ "text/css" \ "text/html" \ "text/javascript" \ "text/plain" \ "text/vcard" \ "text/vnd.rim.location.xloc" \ "text/vtt" \ "text/x-component" \ "text/x-cross-domain-policy" \ "text/xml" </IfModule> # END DEFLATE COMPRESSION
Ask Your Host
First things first: since enabling compression requires you to edit (or even create) a sensitive file that isn’t the easiest to work with (known as an ‘htaccess file‘), if you’re in any doubt about what to do, it may be best to ask your host to do it for you. If you’re with a top-notch host with top-notch support, they should be able to set this up for you (if they haven’t already) within a matter of minutes.
Enable Gzip Compression with WordPress plugin
Here, is some sort of plugin solution to set up Gzip compression. One of the easiest way using a plugin that supports enabling GZIP.
- “WP HTTP Compression Plugin“, This plugin allows you to output the pages in Gzip compressed format, allows your WordPress blog to output pages compressed in gzip. HTTP compression generally means a 60-80% REDUCTION in the size of your pages (broadband usage) as well as an INCREASE in download speeds of 3x to 4x. Download, install and activate ⇒ https://wordpress.org/plugins/wp-http-compression
- “WP Super Cache“, Another plugin option which generates static HTML files from your dynamic WordPress blog. After an HTML file is generated your web server will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts, You can find an option to Compress pages so they’re served more quickly to visitors. Download, install and activate ⇒ https://wordpress.org/plugins/wp-super-cache/
- “W3 total cache“, the most popular plugin which has a great role in optimization of your WordPress site. It improves search engine result page rankings, especially for mobile-friendly websites and sites that use SSL and up to 80% bandwidth savings via minify and HTTP compression of HTML, CSS, JavaScript and feeds. Download, install and active ⇒ https://wordpress.org/plugins/w3-total-cache/
- “WP Rocket“, It also helps to boost the performance of its site without effort and improve the user experience. Furthermore, support is effective and responsive! but also comes with compression built in. Download, install ⇒ https://wp-rocket.me/
Test Your Work
There are a number of ways to check whether or not a site’s files are gzip compressed, with one of the easiest (and most interesting) by using the wonderful GTMetrix site testing tool.
If all is working as it should be, you should be able to see the following within the ‘Waterfall’ section of your site’s GTMetrix results:
Simple!
Update: for a slightly more in-depth gzip check, the website Check GZIP Compression is a handy resource.
Final Words
Gzip compression is one of those simple speed fixes to add (or have added) to your site — whether it be powered by WordPress or otherwise. If you don’t enable it, you could be missing out on a significant speed boost.
Final note: if you’re interested in learning more about a site’s htaccess file, I’d recommend taking a look at the excellent htaccess guide from Tuts+, which includes heaps more info and a number of great tidbits you may be able to use to your site’s advantage.
Pingback: Most Effective SEO Trends To Look Out For In 2018 | DH
Hi Sir,
Its very informative blogs, and really appreciable , we have recently develop website for our company, but the size is around 2.6 MB which is really generate additional loads. Can you please help me out. shall we use plugin as mentioned above or use gzip compression . Kindly help and suggest accordingly
Please contact me at hpsiddhu@gmail.com
I tried editing the .htaccess file but it di not work for me.
The site is not any faster and gtmetrix shows that the gzip compression is not on.
This is a networksolutions site and is very slow. Any ideas?
Check with your web hosting provider if they provide you gzip compression as a part of hosting package.
Upon checking your website, it seems like the modules.ttf and modules.woff files are giving 404 page not found error. These are font files and your site is taking around 7 seconds in trying to open to these files. Your server is also responding slow for the very first ping.
Recommendations –
# 1 check the server path of
++modules.ttf –> /tmp/core/admin/fonts/modules.ttf
++modules.woff –> /tmp/core/admin/fonts/modules.woff
# 2 Talk to your host and ask them if they can fix them and can enable gzip compression on your website.
# 3 Switch to a better host like Hostinger. They provide HTTP/2 and IPv6 enabled, PHP7, NGINX caching, GZIP compression.
let me know if you need any other help.
Hi,
In Cpanel, I also see the Brotli extension in php settings.
Can I activate it to improve speed?
Sorry, I’m not sure but you can try and test..