New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to prevent unnecessary AJAX? #9365

Closed
DavidAnderson684 opened this Issue Oct 15, 2015 · 12 comments

Comments

Projects
None yet
10 participants
@DavidAnderson684
Contributor

DavidAnderson684 commented Oct 15, 2015

I'm currently looking at the performance of multiple WooCommerce-powered websites' home pages.

On each of them, the home page is (or could be) entirely being served from CDNs and caches, except for one PHP call invocation, for WC's ajax call (?wc-ajax=get_refreshed_fragments).

Since the home pages have nothing WooCommerce-related on them - no cart, no products, nothing - this seems like it something that could be optimised away.

I can't see any way to accomplish this. As far as I can see, WC neither attempts to optimise this call away itself, nor provides a way for a site builder to manually force it. As a result, every page on the site, regardless of whether the page has any WC-related content, generates a call to PHP on the back-end. This looks like it may be the largest contributor to server load for many pages, given that, as I say, they're otherwise being delivered from cache/CDN.

Is there any way in which this aspect of site performance can be improved, even if it has to come down to "a site builder has a way to manually force some pages to skip this call" ?

@mikejolley

This comment has been minimized.

Show comment
Hide comment
@mikejolley

mikejolley Oct 15, 2015

Member

De-enqueue the script. WC has no way to know if your page does or does not have a cart widget on it.

Member

mikejolley commented Oct 15, 2015

De-enqueue the script. WC has no way to know if your page does or does not have a cart widget on it.

@mikejolley mikejolley closed this Oct 15, 2015

@DavidAnderson684

This comment has been minimized.

Show comment
Hide comment
@DavidAnderson684

DavidAnderson684 Oct 15, 2015

Contributor

For anyone who finds this, here's an example:

add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11); function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }

Though, personally In think WC could be improved by defining a constant if any of the in-built cart widgets are painted... and then a developer could use that constant to de-queue if he finds that constant not set. (Of course, this won't catch the case of third-party widgets/page elements that rely on it - but they could also start using the constant. And every little helps).

Contributor

DavidAnderson684 commented Oct 15, 2015

For anyone who finds this, here's an example:

add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11); function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }

Though, personally In think WC could be improved by defining a constant if any of the in-built cart widgets are painted... and then a developer could use that constant to de-queue if he finds that constant not set. (Of course, this won't catch the case of third-party widgets/page elements that rely on it - but they could also start using the constant. And every little helps).

@vanhallman

This comment has been minimized.

Show comment
Hide comment
@vanhallman

vanhallman Jan 2, 2017

Hey #DavidAnderson684, Happy New year! Newbie question: Where do I place "add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11); function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }"

vanhallman commented Jan 2, 2017

Hey #DavidAnderson684, Happy New year! Newbie question: Where do I place "add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11); function dequeue_woocommerce_cart_fragments() { if (is_front_page()) wp_dequeue_script('wc-cart-fragments'); }"

@creart40

This comment has been minimized.

Show comment
Hide comment
@creart40

creart40 Jan 7, 2017

Hi @vanhallman you need to add in your functions.php theme. I have tested it and it founds! ;)

creart40 commented Jan 7, 2017

Hi @vanhallman you need to add in your functions.php theme. I have tested it and it founds! ;)

@cranky69

This comment has been minimized.

Show comment
Hide comment
@cranky69

cranky69 Mar 6, 2017

Thank you. but where exactly i need to put this code ? at last line before } ?

cranky69 commented Mar 6, 2017

Thank you. but where exactly i need to put this code ? at last line before } ?

@lukecav

This comment has been minimized.

Show comment
Hide comment
@lukecav

lukecav Mar 31, 2017

@DavidAnderson684

That example works great.

lukecav commented Mar 31, 2017

@DavidAnderson684

That example works great.

@artbox

This comment has been minimized.

Show comment
Hide comment
@artbox

artbox Apr 14, 2017

The placed code is working fine for homepage, but I still can find "?wc-ajax=get_refreshed_fragments" on Posts and some other pages. Did you check them too or there is no problem on your site(s) ?

artbox commented Apr 14, 2017

The placed code is working fine for homepage, but I still can find "?wc-ajax=get_refreshed_fragments" on Posts and some other pages. Did you check them too or there is no problem on your site(s) ?

@Shypixel

This comment has been minimized.

Show comment
Hide comment
@Shypixel

Shypixel Apr 18, 2017

@artbox

Try this - I just put it in place and we're humming along fine with 139k uniques a day.

add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments() {
if (is_front_page() || is_single() ) wp_dequeue_script('wc-cart-fragments');
}

Note: pretty sure this willmuck with things if you have cart notifications and such in your theme, or if you try to embed products or other WC widgets on post pages. But if you know you don't have cart elements on post pages, it'll work.

Shypixel commented Apr 18, 2017

@artbox

Try this - I just put it in place and we're humming along fine with 139k uniques a day.

add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments() {
if (is_front_page() || is_single() ) wp_dequeue_script('wc-cart-fragments');
}

Note: pretty sure this willmuck with things if you have cart notifications and such in your theme, or if you try to embed products or other WC widgets on post pages. But if you know you don't have cart elements on post pages, it'll work.

@jessuppi

This comment has been minimized.

Show comment
Hide comment
@jessuppi

jessuppi Oct 18, 2017

If anyone is interested, we made a free WordPress plugin based on this GitHub issue:

https://wordpress.org/plugins/disable-cart-fragments-littlebizzy/

jessuppi commented Oct 18, 2017

If anyone is interested, we made a free WordPress plugin based on this GitHub issue:

https://wordpress.org/plugins/disable-cart-fragments-littlebizzy/

@blue928

This comment has been minimized.

Show comment
Hide comment
@blue928

blue928 May 21, 2018

We're hitting this issue too with added load times between 1 and 2 seconds. Dequeuing fixes the issue, but what effect will this have on my store? Is this script needed for core functionality? What are the caveats of it not being enqueued? Can something break?

blue928 commented May 21, 2018

We're hitting this issue too with added load times between 1 and 2 seconds. Dequeuing fixes the issue, but what effect will this have on my store? Is this script needed for core functionality? What are the caveats of it not being enqueued? Can something break?

@lukecav

This comment has been minimized.

Show comment
Hide comment
@lukecav

lukecav Aug 16, 2018

@blue928

Do you have mini cart in the header of that store, if not then you will be fine.

lukecav commented Aug 16, 2018

@blue928

Do you have mini cart in the header of that store, if not then you will be fine.

@blue928

This comment has been minimized.

Show comment
Hide comment
@blue928

blue928 Aug 19, 2018

@lukecav Do you mean the little cart icon that can be added to the navigation? We do have that as a part of our menu. It will show a numeric value depending on the number of items in the cart.

https://toursoft.co

If that's what you mean, we're happy to get rid of that to save 1 to 2 seconds of load time.

blue928 commented Aug 19, 2018

@lukecav Do you mean the little cart icon that can be added to the navigation? We do have that as a part of our menu. It will show a numeric value depending on the number of items in the cart.

https://toursoft.co

If that's what you mean, we're happy to get rid of that to save 1 to 2 seconds of load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment