Home Forums WoodMart support forum BFCache conflict with WooCommerce AJAX filters by WoodMart

BFCache conflict with WooCommerce AJAX filters by WoodMart

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #377163

    webreturn
    Participant

    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

    #377188

    Artem Temos
    Keymaster

    Hello,

    Do you mean to include this fix in our theme’s core? It would be better to keep in the child theme to not break cache for other mechanisms and other customers.

    Kind Regards

    #377192

    webreturn
    Participant

    Hi, all other Woodmart webshops have this problem as well, so we suggest to make a fix in the default Woodmart theme? We have 30 licenses.

    #377478

    Artem Temos
    Keymaster

    We will review this and check if it is needed to be added to our theme core. But for now, we recommend you to add this code to your child theme for all websites.

    Kind Regards

    #378041

    webreturn
    Participant

    Hi, oke thank you. Hope you can take a look at it because it is necessary for every website.

    #378266

    Artem Temos
    Keymaster

    OK, you are welcome! Feel free to contact us if you have any further questions.

    Kind Regards

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘BFCache conflict with WooCommerce AJAX filters by WoodMart’ is closed to new replies.