Looking to improve your Magento store loading speed?
Magento 2 Varnish Cache is one way to do it. If appropriately configured, Varnish can speed up the website by 1000 Percent.
The best part, Varnish cache is integrated by default with Magento 2. It only requires several configuration changes to enable it in your store.
Let’s see what Varnish is and how to use it.
What is Varnish Cache and How it Works?
Varnish cache is an open-source web accelerator built for content-heavy websites. Basically, Varnish Cache stores a copy of your website and responds to the requests on behalf of the webserver. It significantly reduces the time to open a page, and users experience a fast-loading page.
When a user enters an URL into a browser, it uses the Internet to send the request to the webserver. The request contains all the information regarding the data the user requested. The data is stored in the database, and the webserver locates it and sends the correct files to the browser. The browser then reads the file and opens the page for the user.
For the user, it is all about clicking on the URL and opening the page. The process should be quick.
Many elements of the website are the same – menu, footer, various designs, repetitive images, and even the text. And if you load the page again, the entire page is the same as before.
That’s where Varnish caching enters.
You install the Varnish Cache on the webserver or separate machine. Once installed and activated, the Varnish cache serves the cacheable assets on behalf of the webserver.
This way, the webserver does not have to respond to the same request multiple times. As the request-response cycle from and to the web server takes more time than the Varnish Cache, the page opens faster.
Advantages of Varnish Cache?
#1 Fast Loading Page
The first and biggest advantage of the Varnish cache is it fastens up the page speed. The page opens faster for the user.
When it comes to Ecommerce, page speed is critical, and if your store is taking more than 3 seconds, you are losing money. For example, Amazon’s sales reduced by 1% for every 0.1-second increase in load time.
#2 Improves User Experience
A study by Akamai and Forrester Research shows:
- 50% of the web users expect a website to open in 2 seconds or less.
- 79% of Ecommerce customers do not return to buy on the site if it takes a long time to open.
A faster Ecommerce store means a better browsing experience, and the customer loves your brand.
#3 High Conversion Rate
The average conversion rate for a website that opens under 1 second is 32%. If it is 1 %, the conversion rate is 20%.
The estimated conversion rates for sites taking 2 seconds to load are at a 12-13% rate.
Basically, the longer your website takes to open, the less satisfied customers will be with it. Eventually, the sales will not be as much as possible.
#4 SEO Advantage
There are more than 200 factors that affect the website’s search engine ranking. Speed is one of the most critical factors.
With Google’s latest update – Core Web Vitals – the speed and user’s experience have become even more important for ranking on Google.
#5 Savings in Infrastructure
Varnish Cache loads the page from the cache instead of the web server – releasing your web server from handling the requests. It saves your infrastructure costs.
Your web app will take more bandwidth and consume more resources without caching. If you are on AWS or Google Cloud, the Varnish Cache can reduce change the infrastructure bill.
Requirements for Magento 2 Varnish
Magento 2 supports Varnish version 4.x, 5.2, and 6.2. So please do check before configuring the Varnish if it is the correct version.
Configure Varnish in Magento 2
The process of configuring Magento 2 is technical and lengthy. You have to install it to the server and then make Magento compatible.
However, if your store is hosted on Breeze, you can enable the Varnish cache easily.
Follow the steps to enable Varnish cache:
- Login to your Breeze platform
- Select the Company you like to work on
- Click on the ‘Sites’ to open the site list
- Open the Store from the list
- Click on the ‘Tools’ option from the left
- Enable the Varnish Cache
A confirmation box will be displayed after the successful activation.
Magento Varnish Verification
Run the following command to verify the Magento Varnish Cache:
curl -IL http://yourwebsite.com/
If the Varnish is activated and configured properly, the result will be:
HTTP/2 200 server: nginx date: Sat, 20 Jan 2021 20:00:21 GMT content-type: text/html; charset=UTF-8 x-varnish: 422754 1293386 age: 44
Besides running the command, you can check the headers to confirm whether caching is working properly.
Open the store, left-click and then select the ‘Inspect’ to open the browser developer tools. Select the Network from the options at the Top.
Select the URL from the ‘Name’ box and check the Headers.
Find ‘X-Magento-Cache-Debug:’ header, and if there is ‘HIT’ in the value, it means Varnish worked.
For Magento 2 stores, you have to enable developer mode to see the Debug Header.
How do I know if Varnish is working?
You can know if Varnish is working by inspecting the response headers. You can also take the help of the online tools that check the varnish caching. Magento developers can also run the command via SSH or check from the admin panel if the Magento Varnish Cache is enabled or not.
Is Varnish free?
Varnish cache is an open-source project that is entirely free. But installing, activating, updating, and managing the Varnish is a time-consuming process. So many hosting companies charge a fee for it. However, if you are on Breeze, varnish comes free with every plan.
Can I use HTTPS?
Varnish is an HTTP accelerator, but it can be used with HTTPS. You have to set up Nginx for reverse proxy and forward all the requests through it. It comes pre-configured with Breeze.
Does the Magento admin get cached as well?
No. The Magento backend is dynamic, and the admin team needs it to always be up to date. Magento admin is not cached with Varnish.
Slow websites suck your revenue. In the modern competitive market, speed gives the edge to the Ecommerce store.
Caching allows your store to have a stable time to first byte and quick page speed. With so many images on the Ecommerce stores, having reliable web performance gets difficult.
That’s why you should ensure to do anything that can affect the website speed positively. Caching is necessary, and Varnish is one of the tools that can take the load off your servers.
If there is any issue in enabling Varnish cache on your store, please leave it in the comment box.