GZIP Compression in WordPress

How to Enable GZIP Compression in WordPress

With changing dynamics of search engine optimisation and growing competition, websites today need faster loading speed. A website’s page speed determines the success of your multiple SEO practices to rank your website among the top SERPs-search engine result pages. One of the initial practices to optimise your site’s page speed is by enabling GZIP Compression. Once that your page speed gets an evident boost, search engines take less time to crawl into your website and analyse it.

What is page speed?

Page speed is the measurement of timespan required to completely load a webpage.

What is GZIP Compression and How it Impacts Page Speed?

Every time a user visits a website, the browser tends to download multiple code files stored on web server and decodes them to display a complete website. By enabling GZIP Compression on a WordPress site, you allow your webserver to provide smaller sized files that take less time to load, this ultimately boosts the page speed. With GZIP Compression enabled on WordPress, the Java script, CSS and HTML files get compressed and minified to provide faster page speed.

How to Enable GZIP Compression in WordPress?

GZIP Compression in WordPress needs to be enabled on the server-side. Many hosting companies like Kinsta and GoDaddy provide GZIP Compression as part of hosting packages, others however, do not. Once that you have determined that GZIP is not enabled on your WordPress site, start with the process.
The only way to manually enable GZIP Compression on a WordPress site is to edit its .htaccess file. Here how you can do it…

  • Create A Backup

Editing a .htaccess file is crucial. To avoid any risk of crashing down your website, create a copy of your original WordPress files and create a secure backup.
The .htaccess file is present in the root folder of your website, however, the file is hidden by default.
To enable access to the file use File Transfer Protocol (FTP) or access them via cPanel. Once that you locate .htaccess file, download it to make changes on your hard drive or start editing it directly. By downloading the file, you lower down the risk of crashing your website.

  • Start Editing

Force hidden files to show and start editing. Add the following code provided by GTmetrix to your .htaccess file:

# 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
  • Save and Run

Save the changes and replace your original .htaccess file. Once those changes are saved, run your website on a GZIP Compression Checker to make sure that GZIP Compression is enabled successfully.
Enable GZIP Compression by using a plugin
Where there is WordPress there is always a Plugin available to make your tasks easy.
WP Rocket is a caching plugin that automatically adds GZIP Compression to your .htaccess file. This makes your WordPress load faster by just a few clicks!
Want to share feedback? Be part of the conversation, comment below!

Leave A Comment