• Resolved jomo

    (@jonathanmoorebcsorg)


    Hi,

    I noticed a site triggering duplicate calls to ?wc-ajax=get_refreshed_fragments
    and traced the problem to:
    ti-woocommerce-wishlist/asset/js/public.min.js

    
        $(window).load(function(e) {
            $(document.body).trigger('wc_fragment_refresh');
        });
    

    WooCommerce is already calling ?wc-ajax=get_refreshed_fragments and then the wishlist may be triggering the same call again before the first call has finished.
    Naturally the result is the same for both calls.

    Since the call is 1s round trip, it’s highly desirable not to duplicate it.
    Would it be safe to just comment this out??

    (also does the wishlist script actually need to be loaded on every single page or could it be limited to relevant pages)

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jomo

    (@jonathanmoorebcsorg)

    Maybe this is attempting to force the refresh on every page load even where woocommerce may not do it? (eg because woo knows from cookie that there is nothing in the cart) – if this is the case then the script can perform the same test, if indeed this is necessary.

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    This appears to have been introduced in version 1.5.9.
    It appears to be related to Wishlist Products Counter, however I don’t even have a Wishlist Products Counter or know how to add one, so in this case the extra call is not needed.

    Unfortunately get_refreshed_fragments is not cost-free functionality, it’s not desirable for a minor point fix release from 1.5.8 to 1.5.9 to add extra overhead to every page load.

    Plugin Author templateinvaders

    (@templateinvaders)

    Hi Jonathan,

    Thanks for the notice. We will improve assets enqueuing and calling WC AJAX fragments in an upcoming update.

    Best Regards,
    Konstantin.

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    why not use a cookie?
    Just update the cookie counter on adding/removing items.
    Then one can avoid extra calls to WC Ajax, this is optimized by WooCommerce to avoid excess calls once it is established that the cart is empty, no need to keep on asking woocommerce to check the cart (which is what the extra calls to wc-ajax are doing).

    Or two cookies, one to record the id of the wishlist for the current user (or zero if none), and another to record the total in the list, like:
    tiw-id={wishlist-id}
    tiw-{wishlist-id}={counter}

    Plugin Author templateinvaders

    (@templateinvaders)

    Hi Jonathan,

    We have just released a new plugin version that includes improvements related to your request.

    Unfortunately, we decided to enqueue assets on all frontend pages because of possible issues with some plugins like a product quick view, etc.

    We don’t want to switch wishlist products counter to cookies because of compatibility with our premium version where dropdown with a list of products available also.

    Best Regards,
    Konstantin.

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    Hi,
    WooCommerce has the mini-cart too, so even for your premium plugin, you can control with the help of the cookie in the same way as woocommerce does.

    Woocommerce does the call once for a new visitor, then if cookie says there is nothing in the cart it knows it doesn’t need to call again on every page.

    In your situation, the same: WooCommerce already does the first call for you which you are hooking, so set a cookie as well.

    Most visitors will not have wishlist items, so the wishlist shouldn’t add this extra overhead for them.
    It’s not just the users who are affected, on many or most installations the server resources are very limited and shouldn’t be consumed on this activity.

    Well I made changes on my side to use cookies and seems to work quite adequately.

    Plugin Author templateinvaders

    (@templateinvaders)

    Hi Jonathan!

    I’ll appreciate if you can share your code so your idea will be clear for our developer.

    Could you contact us via our help page or even make a pull request to our GitHub repository?

    Thanks,
    Konstantin.

    Thread Starter jomo

    (@jonathanmoorebcsorg)

    I have left a detailed note with code examples as an issue in your github:
    https://github.com/TemplateInvaders/ti-woocommerce-wishlist/issues/2

    Apart from 1 line of code this was in my theme and not directly applicable to a pull request without a bit of additional work, especially as I am on 1.5.11 and haven’t had a chance to study the changes since then as yet.

    regards,
    Jonathan

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Duplicate call to ?wc-ajax=get_refreshed_fragments’ is closed to new replies.