Is Nelio A/B Testing compatible with cache plugins?

Absolutely! Nelio A/B Testing will work properly even if your WordPress site is behind a cache system or a CDN. If you want to know how, keep reading.

How do caches and CDN networks work?

The idea of caching is actually pretty simple. WordPress is a content management system and, as such, it runs every time it receives a request and generates the requested page “on the fly,” which will always take some time and server resources. A cache is a system aimed at solving this particular issue: the first time the server receives a request, WordPress runs and it generates the response page, but from that moment on, the cache keeps a copy of this response page and returns it directly, thus preventing WordPress from ever running again.

A CDN is just an extra layer of complexity that follows the same idea: it keeps a cached copy of the response page. The only difference is that this time cached copies are stored in multiple servers across the globe. This way, when a user requests a page, the CDN will serve the page using the closest server available, thus speeding up transfer times.​

This solution, however, comes with its own problems. Essentially, if you change anything in your website and there’s a cached copy in your cache/CDN, the latter will be out of synced and, if the user is served the cached copy, they’ll see “old content.” Cache and CDN systems implement several mechanisms to cope with this: they might keep a cached copy for a limited amount of time only, they might request an updated version on their own and keep it cached, or they might update their cached copies upon request of the WordPress server itself.

But what about split testing in particular?

The challenge of caches

Cache mechanisms are a real challenge for A/B testing. When your website is behind a cache, it’s possible that all your visitors end up seeing the same (original) variant, thus making A/B testing impossible.

Some A/B Testing plugins for WordPress are simply not compatible with caches and make you choose between performance and conversion optimization. Nelio A/B Testing, on the other hand, is not only compatible with caches, but it even makes use of them!

How does Nelio A/B Testing use caches?

When you run a test on a page, our plugin adds a tiny inline script in it. This inline script is basically telling our plugin “hey, this page is under test, these are the variants the visitors might be assigned, and these are the goals and actions that should trigger a conversion.” When a user lands on a tested page, our plugin’s JavaScript files look for this inline script and determines if the current page is under test. If it is, it performs a redirection to a different URL that includes a special query arg:

  1. http://example.com/some-page/?nab=0
  2. http://example.com/some-page/?nab=1
  3. http://example.com/some-page/?nab=2

This instructs our plugin which variant (the original if nab=0 or an alternative version if nab=1 or nab=2) has to be loaded. Thanks to this parameter, your cache system will see different URLs depending on which alternative is being loaded and, therefore, it will cache each alternative as if they were different pages (even though some are just a variant of the former).

This “testing” parameters are added by our tracking JavaScript on the client side. You can read more about how Nelio decides when alternative content has to be loaded and how it’s requested.

Keeping everything in sync

After starting or stopping a test, the cache and CDN networks should be flushed, just to make sure that there aren’t any cached versions of your site in which the tested page is out of sync. Our plugin comes with several hooks to automatically flush the cache of some common cache-plugins for WordPress, but you may need to do this manually.