You’ve probably heard that styles and scripts can have a big impact on site performance. This is certainly true, but these are just pieces of the most fundamental aspect of site performance—the size of your pages.
If you want a faster website, you need smaller pages!
Enabling GZIP compression in your .htaccess
file is one of the easiest ways to decrease your page size and boost your site’s performance.
Here’s what you need to do:
Using an FTP client, edit your .htaccess
file and add the following code after the main WordPress URL rewrite code (the last line should say # END WordPress
):
<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>
After adding that code and saving your .htaccess
file, use this tool to check and see if GZIP compression is working.
If the tool says your GZIP is working, you’re done! If not, delete the code you just added, and then try this code instead:
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
Note: These instructions are for Apache servers. If your site runs on an NGINX server, you’ll need to talk to your host about adding GZIP compression.