How to Enable GZIP Compression to Speed Up WordPress Sites?
Last Updated :
25 Jun, 2024
GZIP compression is the technique that reduces the size of files transmitted between a web server and user browser. This can led to a significantly improve of the website loading times, especially for those with a lot of text, code, and CSS. It falls into the category of lossless compression. The compression process utilizes server resources. While the impact is usually negligible, compressing very large files can cause a slight CPU usage increase.
Benefits to Enable GZIP Compression
- Faster Loading Times: GZIP shrinks file sizes, leading to quicker downloads and a smoother user experience. This is crucial for SEO and user engagement.
- Reduced Bandwidth Usage: Smaller files translate to less data transfer between your server and visitors, potentially lowering bandwidth costs.
There are two main approaches to enable GZIP compression on your WordPress site:
Using a WordPress Caching Plugin
Enabling GZIP compression with WordPress caching plugin is the easiest method. Plugins like WP Super Cache have GZIP compression built in. After you Enable or activate the plugin. It will instruct the plugin to add required code to your .htaccess file, automatically activating compression on your site.
Step 1: Install and activate the caching the W3 fastest Cache plugin.

Step 2: Navigate to WP Dashboard > WP fastest Cache Plugin Settings.
Step 3: In the Settings tab find Gzip and enable the checkbox .
Step 4: Save the changes and you are enabled gzip on your wordpress website

Editing the .htaccess File
This method allows which file types get compressed compared to a plugin method.
Step 1: Log in on your hosting control panel (Ex: Hostinger, Fastcomet)
Step 2: Locate the File Manager section and access WordPress site root directory (often named as public_html).
Step 3: Enable hidden files: Most file managers have the option to show hidden files. Ensure this shall be enabled to view the .htaccess file, which is typically hidden.
Step 4: Locate the .htaccess file and right-click to edit it.
Step 5: Back up the .htaccess file It is crucial to create the backup copy of file before making any changes. Download the file to your computer as an safety measure.
Step 6: Paste the following code snippet at the end of the .htaccess file
XML
# 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
And we add the below code to enable mod_gzip,
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
Note: Editing the .htaccess file requires caution as errors can affect your website functionality. Ensure you can understand the code and follow the steps carefully. Consider using a plugin for a simpler approach if you are unsure about manual editing.
Testing GZIP Compression
Once you've implemented GZIP compression using any of these methods, it is important to verify that it is working correctly.
Step 1: You can use online tools like GZIP compression checker to test GZIP compression and add your website.

Step 2: Click Check button to begin your website's to test the speed and see if GZIP compression is enabled.

Conclusion
Besides editing the .htaccess file, the easiest way to enable Gzip compression in WordPress is with a caching plugin. These plugins offer the easy interface and handle the technical aspects . Popular options include WP Super Cache and W3 Total Cache. They also often have the built-in Gzip compression features alongside other caching mechanisms to boost your website performance.
Similar Reads
How To Enable GZIP Compression in Apache?
Enabling GZIP compression in Apache results in improved website performance and reduced size of the files sent to the client's browser from the server. This will result in faster initial page loads and bandwidth is also reduced. PrerequisitesApache installedAdministrator privilegesFamiliarity with A
3 min read
How to do Compression with Gzip in Node.js ?
We can use the compression module in order to do compression with Gzip compression. Gzip is the most widely used compression, especially for server and client interactions. Compression helps in decreasing the amount of downloadable data in our NodeJS application, and it leads to an improvement in th
3 min read
How to Create a Sitemap for WordPress Site?
A sitemap is  XML file that lists all posts, pages URLs and other content on a website. This helps search engine like Google, Bing to discover and crawl all the pages on a site more efficiently. Creating the sitemap for website is an important step for crawling it for search engines and improving s
3 min read
How to Speed Up WordPress Page Loading Time?
WordPress powers millions of websites globally, but slow loading times can detrimentally impact user experience and SEO rankings. The loading speed of a WordPress site is influenced by various factors, including server performance, theme and plugin efficiency, image optimization, and caching mechani
3 min read
How to Disable the Default WordPress Sitemap?
Creating a custom XML sitemap for your WordPress website can greatly improve your SEO performance, especially when the default WordPress sitemap doesnât meet your specific needs. Here, We will walk you through how to disable the default WordPress XML sitemap and replace it with a custom one using th
5 min read
File Compression in Photoshop using Vector Tools
We all utilize image compression as a daily tool, thus it's essential. Without it, sending enormous files would take hours, we would be emailing hundreds of megabyte-sized files, our landing page would never load, and navigating the internet would feel like walking through thick mud. But being aware
5 min read
How to Install WordPress in localhost web server ?
WordPress is an open-source Content Management System based on PHP and MySQL and used to create a dynamic website. It was developed by Matt Mullenweg and Written in PHP. WordPress is one of the most popular that allows customizing and managing the website from its back-end content management system.
5 min read
How to Bulk Upload Files & Media to WordPress via FTP?
When managing a WordPress site, handling a large number of files or media assets can be challenging. One efficient way to manage bulk uploads is by using FTP (File Transfer Protocol). FTP enables you to transfer files directly to your WordPress site's server, bypassing any limitations imposed by PHP
3 min read
How to clear the Cache in WordPress ?
If you are new to WordPress, learning how to clear your cache is an essential skill. Clearing your cache involves removing outdated data and content from your website's temporary storage, ensuring that you and your visitors see the most up-to-date information. Why Clear Your Cache in WordPress?When
3 min read
How to Optimize Images for WordPress?
A WordPress site is a website formed using the WordPress content management system (CMS). For WordPress users, optimizing images is not only essential for bettering site execution but also for enhancing SEO rankings and tempting more users. In this article, we will study a few simple tips to help yo
6 min read