Using geolocation/geotargeting plugins with WP Rocket
Geotargeting/geolocation features can conflict with page caching.
First, it's important to find out if the geolocation feature is using PHP or JavaScript/AJAX to run.
You can contact the respective plugin support team to get this information. From that point on, please address the following instructions:
Geolocation using JavaScript/AJAX
If the geolocation is JavaScript/AJAX-based then it should work without any issues.
Geolocation using PHP
If the geolocation is using PHP then it won't work as expected.
This is because page cache eliminates all PHP/MySQL processes from a page and creates static HTML output instead.
Specifically, the PHP code will run only once (for the very first visitor) and the resulting code output that will get saved in the cached version of the site. This will result in unexpected site behavior for the rest of the upcoming visitors.
Workarounds for PHP-based geolocation
- You can disable page cache and keep optimizations globally on your site
- You can disable the page cache feature in the affected pages
- If your geolocation feature is using cookies then you might want to try the alternate method below:
Create Different Cache Files with Dynamic and Mandatory Cookies
The article above describes our alternate method you can use to have both geolocation and page cache working on your website. If it can be resolved with just a dynamic cookie, you usually should be able to do this yourself, or we could guide you through it.
If the solution requires something more complex, e.g. a mandatory cookie too, and if it's a widely used geolocation solution, please contact our support team referencing this article so we can assist you further.
Compatible plugin
WP Rocket is currently automatically compatible with the GeoTargetingWP plugin, https://geotargetingwp.com/