• Resolved the_lar

    (@the_lar)


    Hi all,

    I’ve recently activated Litespeed on our site and benefitted greatly from a boost in overall site speed and performance, this has been great for our pagespeed metrics.

    I am now and then having users report issues with our ajax features on the site, such as our tyre search widget which features on our homepage and various others. Basically selecting a Tyre Width or a Tyre Profile always populates and activates the next drop down, but Litespeed is causing 503 errors to be returned from admin-ajax.php.

    I know for sure that this is the cause because as soon as I go to Litespeed and select ‘Purge All’ – it starts working again.

    This issue is NOT present for all users, but for certain it is affecting some of sales guys and a handful of customers.

    Just to note, my ajax requests are sent with the parameter ajax_nonce and in the past I have tried to fix this by adding the following to ESI nonces in section 5 of the settings:
    —–
    stats_nonce
    subscribe_nonce
    ajax_nonce
    nonce
    *_nonce
    —–
    but this hasn’t seemed to help at all.

    Is there any way to simply disable Litespeed on all admin-ajax.php requests?

    Thanks in advance

    Kevin

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support qtwrk

    (@qtwrk)

    please search through the ajax call script , find out the part about “ajax_nonce” you will need to find the nonce name

    Thread Starter the_lar

    (@the_lar)

    Hi there,

    I found this in the documentation – https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi – so I’ve now added do_action('litespeed_nonce', 'my_nonce_name'); just above where I call wp_create_nonce() as it says.

    Is that all I need to do or is there more to it? I only did this late last night, but I have had no more reports of the issue since.

    Thanks

    Plugin Support qtwrk

    (@qtwrk)

    yes , or you can add the my_nonce_name to the ESI nonce list , but this requires your server supports ESI

    Thread Starter the_lar

    (@the_lar)

    Perfect, thank you! As I say, haven’t had any re-occurance since I put this in place 2 days ago… fingers crossed!

    Thread Starter the_lar

    (@the_lar)

    Hi again,

    Just picking this up again as I have had a re-occurrance of the issue and I managed to get the user to give me some screenshots which I’d like to share.

    Firstly, just a bit of background on my setup – our site is based on roots/sage theme 9.0.9. In my setup.php file I have the following code snippet:

    /**
     * Theme assets
     */
    add_action('wp_enqueue_scripts', function () {
        wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
        wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, false);
    
        // Litespeed
        do_action('litespeed_nonce', '<my_nonce_name>');
    
        $ajax_params = array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'ajax_nonce' => wp_create_nonce('<my_nonce_name>'),
            'asset_path' => asset_path(''),
        );
        wp_localize_script('sage/main.js', 'ajax_object', $ajax_params);
        ...
    }

    Obviously I’ve changed my actual nonce name to <my_nonce_name> in the code above.

    As you can see, I’m calling litespeed_nonce before calling wp_create_nonce() as instructed here – https://docs.litespeedtech.com/lscache/lscwp/api/#convert-custom-nonce-to-esi

    My Javascript code where the ajax call is made is:

    $button.bind('click', function(){
        console.log('size search button click');
        $button.addClass('loading');
        let data = {
            action: 'postcode_check',
            // eslint-disable-next-line no-undef
            nonce: ajax_object.ajax_nonce,
            postcode: $tyre_postcode.val(),
        }
        $.ajax({
            // eslint-disable-next-line no-undef
            url: ajax_object.ajax_url,
            type: 'POST',
            data: data,
            dataType: 'json',
            success: function (response) {
                ...
            }
        });
    }

    As you can see I’m accessing the ajax_object that was registered when localizing the script in setup.

    Finally, my PHP script for postcode_check has check_ajax_referer as the first line of the function and looks like this:

    add_action('wp_ajax_nopriv_postcode_check', [$this, 'postcode_check']);
    add_action('wp_ajax_postcode_check', [$this, 'postcode_check']);
    
    public function postcode_check()
    {
        check_ajax_referer('<my_nonce_name>', 'nonce');
        ...
    }

    The part of the site where the issue occured for this particular user is on our homepage, interacting with the Tyre Search widget which is at the top of the page:

    When the user selects a tyre width, tyre profile and tyre size, then enters their postcode – clicking ‘See Products’ performs an ajax request to the above postcode_check function. It is this ajax request that is failing for the user.

    I have managed to capture the following screenshots of the request in Firefox web console from their laptop.

    Request headers:

    Request:

    Response:

    As you can see, the request to postcode_check is giving me a 403 error.

    Notably when I tried just clearing the Litespeed cache alone, the users error persisted. It wasn’t until I commented out the check_ajax_referer code in the PHP function that I was able to clear the users error.

    Hope that the details above will enable me to get an idea of what is causing these intermittent issues.

    Many thanks

    Plugin Support qtwrk

    (@qtwrk)

    please provide the report number , you can get it in toolbox -> report -> click “send to LiteSpeed”

    Thread Starter the_lar

    (@the_lar)

    Hi there, report number is LCFHTFTM

    Kevin

    Plugin Support qtwrk

    (@qtwrk)

    hmmmm? is that nonce name in ESI nonce list the one you use ?

    for instance I don’t see any issue

    please try enable debug log with include URI as lsesi , this is subrequest from ESI that will send to plugin , it should come with 30 minutes of TTL , please enable log and see what actually occurs

    Thread Starter the_lar

    (@the_lar)

    Hi there,

    Do you mean the one that starts with ‘4×4’ which is 3rd in the list?

    That’s the same one from where I am doing this in my code:

    do_action('litespeed_nonce', '<my_nonce_name>');

    but I’ve removed the actual name and replaced it with <my_nonce_name> – I wasn’t sure if it needed to be in the ESI nonces list so that is why I put it in there.

    Could you explain the process of enabling the debug log using lsesi to me please – is it something I add to the URL? And where do I see the log once it has been activated?

    Many thanks

    Kevin

    Plugin Support qtwrk

    (@qtwrk)

    please go to toolbox -> debug setting -> set debug IP to ALL , log level to advance , debug include URI , add lsesi into the field

    Thread Starter the_lar

    (@the_lar)

    OK I will do that now.

    I may have had a bit of breakthrough – I have just triggered the error myself and captured this screenshot of the Firefox console which gives some additional information:

    Does this help?

    Thread Starter the_lar

    (@the_lar)

    Hi, on the debug settings, I have set it up like this:

    But as you can see it’s saying Invalid IP when I add ALL to the field – but maybe that’s not what you meant?? Also, should lsesi be in the Debug URI includes field like that?

    Thread Starter the_lar

    (@the_lar)

    Ugh… images expired in previous messages, here is the firefox console again –

    And here is the Litespeed debug config as I’ve set it up –

    Hope these help

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Intermittent ajax issues using plugin’ is closed to new replies.