A webshop we have made using WoodMart had issues whenever we selected options, a part of the page got refreshed through XMLHttpRequest with the same request URL as the page itself, causing the response from the XMLHttpRequest to be stored in the bfcache (back-forward cache).
This caused issues as we clicked on a product, and went back using the browser’s back-button – the last cached response from the URL of the previous page was used to able to load the previous page. That last cached response was the response of the XMLHttpRequest, which is a part of the page.
So a broken shop page was shown when clicking the browser’s back-button.
I was able to fix this by preventing the browser from caching requests that were requested through JavaScript’s XMLHttpRequest method. This is the PHP-code:
add_action(‘send_headers’, function() {
if ( // Prevent AJAX requests from being stored to be used in bfcache (back-forward cache)
isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) &&
strcasecmp($_SERVER[‘HTTP_X_REQUESTED_WITH’], ‘xmlhttprequest’) == 0
) {
header(‘Cache-Control: no-cache, no-store’);
}
}, 9001);
Could you use this code to fix this issue? This issue did not happen on our WoodMart webshops that used caching tools such as WP Rocket.
Best regards, Tim