GZIP compression in WordPress

GZIP compression reduces the size of HTML, CSS, JavaScript and XML files sent from your server to increase the speed to which they are transferred to the browser. Gzip compression in WordPress reduces up to 90% size of your site. Important step for your page speed, because it reduces the time it takes for a website to transfer the page files and style sheets. In terms of cost versus benefit, gzip compression MUST be near the top of your page speed optimizations if you don’t have it setup already. I save 74.9% with Gzip enabled on my website. You can use this tool to check.

First of all, you need to check if you use Apache or Nginx server. Gzip compression is used on Apache and Nginx servers, while Deflate is only used on Apache server. Most servers are Apache.

Compression on Apache server

Add this in .htaccess file for Gzip compression

# BEGIN GZIP COMPRESSION

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.*

# END GZIP COMPRESSION

Deflate mode

# BEGIN DEFLATE COMPRESSION

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"

# END DEFLATE COMPRESSION

Compression on Nginx server

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;

Conclusion

As I mentioned, this is a very important step to increase your page speed and loading time. You can save up to 90%. If you have not implement it yet, get on your keyboard and do it immediately. Remember to check your results in GTmetrix, Google Pagespeed Insights or checkGzipcompression.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.