Updated on Mar 13, 2019
Method Type: Server
(this means that this method is handled by the Server side configuration)
Status: Enabled by default on all FastComet Hosting Servers.
Introduction:
Gzip is a file format and an application used for file compression and decompression. It is based on the DEFLATE data compressions algorithm.
How gzip compression works:
Gzip compression reduces the size of web files by compressing them. Then it sends the files to the requeston(user opening a page) and the web browser of the requestor receives the compressed files. The web Browser decompresses them automatically and provides the content of the page to the requestor. This saves a lot of time as the user has to download much less in order to receive the same content which you have provided on your website.
Gzip compression doesn't improve loading speeds when the web browser has to load binary formats like images and can actually slow the loading of the page if it tries to compress such files. This also loads the CPU of the web server for no purpose as its not beneficial for the end user.
It is worth noting that some external elements will not be compressable and will give you a lower score for that.
Gzip compression provides the following Advantages:
Gzip compression has the following Disatvantages:
Gzip provides compression and saves a lot of time from the page loading cycle. It is enabled by default on all FastComet Hosting Servers. However, if you want to enable gzip compression on your own server you can do so via the .htaccess file by adding the following lines to it:
<IfModule mod_deflate.c> 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 </IfModule>
Another way to enable gzip compression is by adding the following lines to your vhosts.conf/ httpd.conf
file:
<IfModule mod_deflate.c> 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 </IfModule>
You will need to rebuild the Apache Service afterwards.
If you are using NGINX add the following lines to your config file. You can access the main configuration file via SSH by navigating to:
/etc/nginx/conf.d
gzip on; gzip_comp_level 2; gzip_http_version 1.0; gzip_proxied any; gzip_min_length 1000; gzip_buffers 16 8k; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
You can change the gzip_types according to the MIME types you wish to compress. By default NGINX only compresses the MIME type text/html
.