Although this article was written for users of the CCA plugin; it applies to other plugins that modify content and adverts based on the country of your visitor.

If you don’t know what a caching plugin is, then you probably aren’t using one and can ignore this page.

If you only wish to use the CCA plugin to display different content for different categories then you can ignore this page.

If you wish to cache and use visitor country location: then I recommend you use either the Zen Cache/Quickcache or WP Super Cache plugin, with the country caching extension.

In this section:

1. Why caching plugins don’t work well with dynamic content
2. Solutions and work rounds
    2a. ZenCache/QuickCache <(recommended)
    2b. WP Super Cache <(recommended)
    2c. Cloudflare and other CDN’s <(recommended-ish)
    2d. Other Caching Plugins
3. If all else fails
4. Testing caching and country location (beware pitfalls)

1. Why caching plugins don’t work well with dynamic content

Before WordPress delivers a page to the visitor a lot of scripts are run to build the page; this may take micro seconds or seconds. Caching plugins save time by by-passing the building of the page, and instead serve a snapshot (cache) of the page as it was created for the “first” vistor.

This is okay for static pages but not for dynamic content e.g. if you are using the WordPress RSS widget and your page was snapshot (cached) 3 days ago, your news feed has in effect become a 3 day old history feed.

Caching is a problem for Country geoLocation plugins which serve “dynamic content”. e.g. A widget may be configured to display an Amazon.DE advert to German visitors, and one for Amazon.COM to all other visitors. However; if the cache was created when the page was visited by someone from Germany then the snapshot will contain the Amazon.DE advert and ALL subsequent visitors will see this German version of the page.

N.B. Using the CCA widget for categories only is NOT a problem. e.g. If your widget is set to display a hotel search form on posts in category Travel (visitor from default “anywhere” only); then the hotel form will be included whenever WordPress has to build the page, and consequently in any cache snapshot.

2. Solutions and work rounds

2a. Zen Cache/Quick Cache

Zen/Quick Cache is designed to enable developers to add extensions to modify caching behaviour. The free Country Caching extension plugin makes ZC/QC cache by page + visitor country instead of just page. With this extension ZC/QC should work perfectly with country geo-location.

More info: Country Caching extension for ZC/QC (the guide).
Get the plugin via your WP dashboard or download here on WordPress.Org

2b. WP Super Cache

Install the Country Caching Extension for WPSC.

Super Cache is also designed to enable coders to add extensions to modify caching behaviour. The free WPSC Country Caching extension plugin makes WPSC cache by page + visitor country instead of just page. With this extension QC should work perfectly with country geo-location.

More info: Country Caching extension for WPSC (the guide).
Get the plugin via WP dashboard or download here on WordPress.Org

2c. Cloudflare and other CDN’s

I use Cloudflare and have configured it to use “agressive caching” this caches static content like images and CSS. This works fine with the CCA plugin. I do not recommend use of other caching options.

Other CDN’s have similar facilities and their equivalent of Cloudflares static content caching should work well with the CCA plugin.

2d. Other caching plugins

The other major caching plugin is W3 Total Cache. It does not currently enable the use of extensions so it is impossible to produce a cache by page+country add-on like I’ve done for WPSC and Zen/Quick Cache (above).

If you are a confident coder, you can modify W3TC to cache by page+country, but your code modification would be lost every time you update to a new version of W3TC. I will do a “how to” on this in a later article.

Most of the popular caching plugins allow you to specify pages/posts that must not be cached. This is fine if you are only serving a couple of posts that serve different customized content depending on visitors country. It may also be fine if your sidebar widgets (CCA or others) only serve different country related content for posts in a category with a small number of posts.

However, if your sidebar widget content is visitor related throughout your site then you would have to disable caching on most pages – making the use of a caching plugin pointless.

Some plugins also allow “fragment caching” which enables you to identify snippets of code that should not be cached. These might work fine on simple code snippets like “echo date(‘Y-m-d H:i:s’)” but I suspect you may get unexpected results if you try “fragment caching” on code that uses variables or that requires say class instances such as a sidebar widget. If anyone has an example of a sidebar widget that has been fragment cached I’d love to see the code.

QuickCache (ZenCache) and WP Super Cache allow you to write extensions to modify their caching behaviour; and this is the feature my country caching extensions (above) use. You may find other plugins offer similar hooks for extensions (please let me know) and you can write your equivalent.

If all else fails (CCA plugin only)

Just use the plugin for categories i.e. always set the Country selector of your entries to the “any/other” default.

Caching and country location testing (beware pitfalls)

Pitfall: many caching plugins will serve you a virgin UNcached page if you are logged in as admin (or ANY user). Some will serve you an UNcached page if you have PREVIOUSLY been logged on. If testing, make sure you are NOT logged in and have deleted all cookies. As I have never used it to log in to my site, I use the “360 Browser” for testing,

If you are using the WPSC or Zen/Quick Cache extension there is a simple way (WPSC | ZC/QC ) to check county caching. Otherwise:

I’m based in England so I see my site the same as any other British visitor. To see how my site’s pages appear to a US visitor I go to proxyUSA.Org and enter my site URL’s there. If you use this proxy for testing make sure you untick the “remove scripts” option as most WP sites need javascript to display correctly.

If you are based in the US then Google search for proxy servers that do the same job for other countries. Warning: not all of these actually use IP addresses for the country claimed – I used a so called Australian proxy that actually had a US IP address – if you get unexpected results check the IP address used by the proxy.

If you cant find a suitable proxy some online site speed test sites allow you to specify servers in different countries and will display small snapshots of pages generated.

If you have a “TOR browser” and know what you are doing you can use it to see what your site looks like in a variety of countries.