You probably already visited a website that took forever to appear. With today’s stuff schedules, we no longer have the patience or time to wait after a web page to load.
Even worse if you are a webmaster and you need to optimize a site running a WordPress website. To satisfy your customer’s demands and search engines like Google, your nightmare is just about to begin!
Varnish Cache is an “open source” software that provides an interesting and effective solution for this problem.
First, we must understand that today’s websites are created with content management system (CMS) like WordPress and many others. Although practical and flexible, they are usually much slower than the traditional site (also called static). Each page viewed will open a few hundred files and will make several queries to a database. Each of these actions costs precious milliseconds of delay before displaying the page.
This is where Varnish comes into action!
Varnish Cache will work between your customers and your site. When a customer visits your site, Varnish takes a picture of it and shows it to the customer. When a second customer visits your site, Varnish will simply show the picture of that page. This prevents querying to the content management system one more time (like WordPress).
The comparison can be imaged as follows.
Let’s say you are receiving friends Monday for lunch and you do not have a table, you go out, take your car and buy a table. Once the visit has left, you throw the table away. The next day, you are receiving another friend for dinner, you the go back to the store and buy a new table.
With Varnish, the first day you buy a table, but the following days you use the one you already bought, which is a lot faster than returning to the store!
Let’s see briefly the geeky technical information
Since a few months ago, the version 5.2 of Varnish is now available (some may say that the version 6.0 is available since March 15, but since it is a paid version, I will not refer to it) and brings very interesting and expected technical improvements.
HTTP/2 protocol support:
The HTTP/2 protocol (or H2 for the intimates) is the first update of the HTTP protocol since 1997 (HTTP represents the method that the web browsers use to display the page).
This protocol alone will reduce the number of coming and going requests between the hosting servers and customers. In the past, Varnish could not understand the request sent by the HTTP/2 protocol. Now Varnish will not only speed up the requests sent to your site, it will also benefit from the latest advanced HTTP.
Multiple VCL configuration files:
With version 4.X of Varnish, all the configurations and tweaks had to be contained inside a single VCL files. From now on, it is possible to have several configuration files and load or remove them in real time. For a webmaster, this will greatly facilitate the creation of development environments or add the possibility to easily host multiple sites on the same server.
Varnish cache is a very versatile tool (although it can sometimes be quite complex to configure) and can greatly help to improve a website load time. I’m currently the webmaster for a site receiving more than 1.2 million unique visitors per day. When I was initially approached, the owner of the site was running out of solution since no one could help him speed up his site. Today, despite the huge traffic that his site generates, his web pages open almost instantly.