Open In App

How to Enable GZIP Compression to Speed Up WordPress Sites?

Last Updated : 25 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

gzip1

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

gzipwordpress2

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.

gzip3

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

gzipwordpress4

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.


Next Article
Article Tags :

Similar Reads