Magento 2 and Varnish…

I’ve been working on getting our new website moving quicker. We have a large catalog and some semi-fancy functionality that slows things down a bit. I tried installing redis and turning that on. It works well, but for page caching, it just wasn’t quite enough. I have now turned my attention to varnish.

Describing varnish to my peers was tough. They don’t care much about technicalities, they are marketers. I described what we had in redis to either a Camaro or Mustang. I then told them to think of varnish as a Bugatti. If you’re not familiar with Bugatti, they’re among the fastest cars in the world.

Magento 2 has built-in support for varnish. They provide a .vcl file for both varnish 3 and 4. It’s a simple setup in that regards. It only took an hour to get varnish installed and Magento setup. That included reading through Magento’s docs and my host’s instruction on installing varnish.

I fired up the web site, clicked a few links, and I was flying from page to page. Here is what I found as far as positives:

1. After clicking through 3-4 pages, the site was moving very fast.
2. I only had to make one adjustment to a layout file to get something to show back up.
3. Magento did a good job understanding what shouldn’t be cached.

I was very happy at this point. I didn’t have broken pages and was able to make a quick list of challenges. These are revolved around custom blocks that we had created. Those were getting stuck in cache.

I started taking the approach of going through my layout files and adding cacheable=”false” to specific blocks. This helped some, but not all of them.

I’m still working through that list of stubborn blocks to see where we have things a bit off. Other than that, I’m endorse this solution to anyone.

Here are a couple of recommendations for installing and configuring it:

1. Read the Magento 2 devdocs.
2. Check with your host if you don’t know how to install varnish on your server.
3. Stick to your development environment first.
4. Understand there will be block caching problems and make a list to work through.
5. Understand you might have to work through a module issue.

If you’re looking for a good performance boost, don’t shy away from varnish. You’ll need to plan, test, and fix a couple of things, but the rewards will be there in the end.


Written by Dan
Welcome to my blog! Here you'll find my collection of bible study lessons, book reviews, and other posts I feel inspired to write. I am a Christian currently serving in different areas of SE Michigan.