You are here:

Cache and Geotargeting

By general rule page cache is incompatible with geotargeting. By definition page cache is like a snapshot of all your dynamic content saved into an HTML file.

That means that if you place for example a shortcode to display the user country and the first user that visits the page is from Argentina, the next user will see the cached page and will show also Argentina.

To avoid that you need to exclude that page from cache and that's how normally works in WordPress.

Cache with GeotargetingWP

On GeotargetingWP plugins we tackle page cache in different ways. The most important one is that we are compatible with a couple of cache plugins.

WP Rocket: It's 100% compatible and it's the one we recommend. By default it creates a different cache version for each country. If you need to create different cache pages for cities or states you will need to add some code in your site. You can extend this with filters for states or cities but be aware that enabling it will decrease performance in cache and more cached version of each page needs to be generated.

Also because WpRocket uses cookies to handle this and cookies needs to be set before any content is print we need to calculate geolocation at the very beginning. To do that you need to enable cache mode. If you don't want to enable cache mode you need to disable WpRocket cookies or your cache will break

Extend cookies or disable them entirely

Wp Super Cache: The plugin is managed by the company behind of WordPress and it's a really solid plugin. In order to use it with our plugins you need to use PHP legacy mode and enable late INIT option. That will have the page cache run after the plugin detects the user. (Not available in all hostings)

Ajax mode

The GeotargetingPro plugin have something called ajax mode that makes it compatible with any cache plugin. It will basically run an ajax call once the page it's loaded and update the content with simple javascript.