Gzip Compression
Gzip Compression

You may have noticed in Google’s PageSpeed Insights that some websites are flagged up for not enabling compression, as seen below.

Compressing Files With Gzip

WHAT EXACTLY IS GZIP COMPRESSION?

The simple’s way to explain Gzip compression is by imagining you ordered a new dinner table. Once it arrives it will be packaged and dismantled, you’ll be required to set the table up yourself. Gzip compression works in a similar way but with computer bytes, the server will compress steams of bytes such as spacing within HTML, CSS or JS files and send them across the web. Once the files are downloaded by your browser, the browser will uncompress these files. This simple feature can yield significant page speed improvements and reduction to page size.

Gzip compression works in a similar way but with computer bytes, the server will compress streams of bytes such as spacing within HTML, CSS or JS files and send them across the web. Once the files are downloaded by your browser, the browser will uncompress these files.

This simple feature can yield significant page speed improvements and reduction to page size which can help improve SEO performance.

ENABLING GZIP COMPRESSION for Apache

The code below should be inserted into your .htaccess file that usually lives in the root of your website.

AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

 

ENABLING GZIP COMPRESSION for Nginx

The following can be placed in your nginx.conf file, usually located at /etc/nginx/nginx.conf or in your virtual host configuration file. Usually located at /etc/nginx/sites-available/domain-name

 gzip on;
 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_buffers 16 8k;
 gzip_min_length 256;
 gzip_http_version 1.1;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

LEAVE A REPLY

Please enter your comment!
Please enter your name here