One of the Most important information about speed of website in this section we cover why compression is so vital and how it can hit your website.
Before delving any more it is very important to know what compression is. It is an algorithm and it can assist to remove needless redundancy from file and it proves valuable in creating a file which is of lesser size, as compared to the real representation. It is the application possible on both ends; appeal and reply, provided the browser and the server, both are capable to understand the algorithm.
It is indicated in web browsers that compression is supported in headers which are forwarded to servers in HTTP request. This header is then visible to web server in request. In case it is possible, then it can even try to apply compression to the response which is sent back.
Ease of implementation is a prime reason why compression is preferred and used these days. Before you can go ahead and start implementing compression, it is important to understand its different types which are available.
A close look at the above presented HTTP request will assist you notice the header, named Accept-Encoding, and sent by the browser. Through this header the server is being notified that compression is supported by it. In fact here the compression isn’t one type but incorporates more types. Header is also signifying the server that Gzip, SDCH and Deflate are supported by it.
Your browser might support any from different types of compression and depending on this type the content will be compressed by the server accordingly, before returning a header in HTTP response. Content-Encoding is the name of header and as seen the above figure, a response has been sent by the server stating that the data has been compressed in the Gzip format.
Why compression is a good option to use?
For testing the effectiveness and efficiency of compression, as well as the way it can impact various file types, some common files have been taken and compressed with the help of Gzip.
In the above table the variation in the size of files, prior to applying compression and afterwards, has been highlighted. In some files the difference is as massive as around 75%. The working of Gzip compression is based on finding same strings in a specific text file, while temporarily replacing the strings for reducing the overall size of the file.
This particular type of compression can be considered more suited for web. This is because CSS and HTML files commonly have many strings which are repeated, such as tags, style definitions and whitespace. Even if you take a look at the table presented above, then it is clear that the text files involved bigger savings, in comparison to the image files. The reason behind this is that the image files have been compressed already and even if more compression is applied then there will be no significant benefit.
Besides, direct correlation can also be seen among the file size and the extent of savings. Generally, it is considered that large files involved better savings. The reason for this is that it is easier for the server to compress big files as these contain more character repetition and whitespace. If you use Chrome Developer then you will come across a tool which lets you see, as well as compare the variations before and after the compression is applied.
So, these are a few tricks which can be used for your site quick. Even if your site seems fast already, you can still make a considerable change by implementing these tricks.