Answers

We’ve gathered common questions about Magento and are happy to share our answers.

Answers
Staylime’s related service

What is Varnish in Magento?

In Magento, Varnish is an HTTP accelerator that can be used as a caching reverse-proxy for a web server by caching static files and serving them instantly when requested by a client device. It can speed up the delivery of a website’s content by a factor of 300 to 1000x, depending on the underlying architecture.

What is Varnish?

Varnish is an open-source web application accelerator developed by Poul-Henning Kamp in 2006 for boosting the performance of content-heavy websites and APIs. Unlike other web application technologies such as Nginx that also act as an HTTP cache, Varnish is designed purely as an HTTP accelerator and it doesn’t support additional network protocols such as FTP and SMTP.

Varnish and Magento

Magento store owners have been using Varnish to boost their website performance for years. However, it wasn’t until Magento 2 was released that merchants could leverage the technology without requiring any additional modules.

Before Magento 2, retailers seeking to use Varnish relied on an extension called Turpentine that allowed Magento stores to use Varnish properly. This was needed because, by default, Varnish didn’t cache requests that contained cookies, and Magento 1 would include frontend cookies with requests leading to an almost zero hit-rate for the website cache.

Turpentine was developed to modify Magento’s default behavior and to boost the cache hit rate. However, even with the extension, developers were often required to add custom edge-side-includes (ESI) policies for blocks introduced by their extensions. This increased the time and costs for custom development significantly.

Since the release of Magento 2, merchants can now use Varnish for their stores without relying on any additional extensions. Adobe has included a module inside Magento that outputs a ready-to-use configuration file that enables stores to work with Varnish caching.

How Varnish caching works in Magento

Magento 2 stores leveraging Varnish generally work using three configuration files:

  1. nginx.conf.sample
  2. .htaccess
  3. default.vcl

The first two are included by default with all Magento installations, while the third must be generated through the Magento admin panel while configuring Varnish to work with Magento.

The first time a user visits the frontend of a Magento website using Varnish for caching, all client-side cacheable assets are delivered by Varnish using the options provided in the nginx.conf.sample and .htaccess configuration files to be cached by the client’s browser.

The second time the browser requests the same page, all cached assets are delivered from the browser reducing the amount of data that needs to be transferred from the origin server and increasing the page load speed.

Varnish uses an entity tag for static assets to determine when files have changed on the origin server so the browser requesting the file can be served with the latest version. An entity tag, or ETag, is one of many web cache validation mechanisms used as part of HTTP.

Essentially, Varnish assigns each version of a cacheable object a unique identifier that can be validated when loading a page to avoid downloading previously cached objects and to refresh any stale cache. This makes the entire caching mechanism significantly efficient while also reducing bandwidth usage.

Why use Varnish in Magento

One of the most significant benefits of using Varnish in Magento is the performance boost it provides. When implemented and configured correctly, Varnish can bring the page load times down to as little as 1 to 2 seconds, with the only limiting factor for performance being the end user’s internet connection.

A study conducted by global telecommunications giant Telefonaktiebolaget LM Ericsson showed that consumers experienced stress that was equivalent to watching a horror movie when browsing a slow website. Using Varnish will boost your website conversions by reducing the stress customers would otherwise experience with a slow loading and sluggish website.

Furthermore, the performance and conversion boost will also translate to better search engine rankings as Google’s primary ranking factors are performance-related and focus on improving the end-user experience. With better performance and conversions than your competitors, Google will view your website as an authority in your domain and boost your organic rankings sending more traffic your way.

Ready to use Varnish with your Magento store?

Adobe has provided detailed documentation for installing and configuring Varnish to work with Magento. They’ve broken down the entire process into easy steps that can be followed by those who are familiar with server management and Magento.

Although they still allow using the default caching mechanisms, i.e., filesystem, database, and Redis, implementing Varnish for the website cache is strongly recommended as Magento is designed to work with Varnish.

Using it with your Magento store will allow you to experience the true performance capabilities of the platform and give your business a significant edge over your competitors.