Varnish and WordPress, Corner Cases

The Corner StuffWordPress Varnish Corner Case

My previous Varnish and WordPress post, Make WordPress Faster with Varnish Cache, was good introduction how to get your site fast. It still left some cases untouched. In this post I will look into these cases and fix them. Cases include some Varnish and WordPress configurations.

WordPress Caching with W3 Total Cache

This is very popular caching plugin for WordPress. It has lot’s of features that we can take advantage of. Why I’m installing another cache behind  Varnish? Well, they do not rule each other out. Varnish will use it’s cache better if server sends proper browser caching values. By default, WordPress will not take advantage of browser caching. With this, we can reduce requests to server and have proper TTL values for objects in  Varnish Cache.

Go ahead and install W3 Total Cache. It includes loads of features by default so don’t get exhausted. Take your time and browse around what’s where. You can find all the option from left side under Performance Menu.

W3 Total Cache also includes minifying tools so I uninstalled Better WordPress Minify. There’s loads of guides how to tune settings, so I’m not going to do that. Bare minimum you should be enabling is: minifying, page cache and browser cache.


Disable Caching for Logged In Users

You don’t want to cache content of your logged in users. Long story short: add this to your policy file.

Disable Caching for Search Results

Repeating my self: Don’t cache search results: add this your policy file.

Normalize Accept-Encoding Headers

By default, Varnish 4.0 will tamper your requests to add Accept-Encoding header to your requests. There’s still caveat on this. Browsers send Accept-Encoding headers different order and all get their own hash bucket in Varnish Cache. Waste of resources. Also we do not want to compress again compressed object. So, go ahead and add this your policy:

Graceful Content Refresh

If you use default configurations for refreshing of objects, you might get small delay when refreshing content from back end. This is why we must allow Varnish to fetch content asynchronously and replace object gracefully.

This is how it’s configured.

Health Check

One of the core features of Varnish Cache is to shield from misbehaving back end servers. Here’s basic configuration to enable health check.

Varnish and WordPress, Corner cases

In this post I’ve shown some cases that makes your web site even more stable and fast. Again you can find sources from Github.

Leave a Reply

Your email address will not be published. Required fields are marked *

9 − nine =