Gain More Speed!

Jin Jie

Member
All my images are now fully optimized, but I still found a way to increase my page load speed, and this makes quite a large difference.
Disable Cart Fragmentation on Front Page (Best to disable on the front page only, as you will want to load this as fast as possible. In some cases Cart Fragmentation can add up to 10 seconds! ) I am down to 1.6s fully loaded with 400 products, Elementor Pro, Astra Pro, 18 plugins.
In WordPress admin panel, navigate to “Appearance > Editor” and locate the functions.php file. (Or edit the file in cPanel File Manager). Add the following code at the end of the file. (I use a child theme)
/** Disable Ajax Call from WooCommerce */
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'); }

If you test your site with GTMetrix and look at the Waterfall, you can see if you need it or not. (I saved 1.2s)
(wc-ajax=get_refreshed_fragments)
 

Attachments

  • GTMetrix_18.07.JPG
    GTMetrix_18.07.JPG
    268.7 KB · Views: 42
Last edited:
  • Like
Reactions: Mar

Mar

Moderator
All my images are now fully optimized, but I still found a way to increase my page load speed, and this makes quite a large difference.
Disable Cart Fragmentation on Front Page (Best to disable on the front page only, as you will want to load this as fast as possible. In some cases Cart Fragmentation can add up to 10 seconds! ) I am down to 1.6s fully loaded with 400 products, Elementor Pro, Astra Pro, 18 plugins.
In WordPress admin panel, navigate to “Appearance > Editor” and locate the functions.php file. (Or edit the file in cPanel File Manager). Add the following code at the end of the file. (I use a child theme)
/** Disable Ajax Call from WooCommerce */
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'); }

If you test your site with GTMetrix and look at the Waterfall, you can see if you need it or not. (I saved 1.2s)
(wc-ajax=get_refreshed_fragments)
Tried the code. It gained load speed but with a number of issues as a result. All plugin updates failed, Alidropship Auto update page don't work, the page is blank. Items in the cart is not showing with the cart icon, only show when you open the cart and editing products is not working well, cannot open variations, cannot import reviews. I deleted the code, everything went back to normal. At least at my end.
 

Jin Jie

Member
Oh Dear, sorry to hear that! I hope you won't blame me:eek: I do not understand what happened in your case, but it certainly worked for me.
I guess it's not for everyone. Sorry again for your trouble!
 

Mar

Moderator
Oh Dear, sorry to hear that! I hope you won't blame me:eek: I do not understand what happened in your case, but it certainly worked for me.
I guess it's not for everyone. Sorry again for your trouble!
I am not blaming you. It worked for me with load speed but with undesirable effects mentioned.
 

Mar

Moderator
Oh Dear, sorry to hear that! I hope you won't blame me:eek: I do not understand what happened in your case, but it certainly worked for me.
I guess it's not for everyone. Sorry again for your trouble!
I just saw the core actions of admin-ajax.php. update-plugin is one of 88 actions, This explain why I cannot update plugins with the codes active and I am sure it is not only at my end.

1563505125691.png
 
/** Disable Ajax Call from WooCommerce */
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'); }
. . .
(wc-ajax=get_refreshed_fragments)

There are actually 3 versions of the code for use depending on what you need - here's the blurb from webnots.com which kind of lays it all out! Take your pick.

If we could somehow delay/defer all these admin-ajax calls (ADS' Countdown, Recent PopUp and Upsell add-ons all add to the load time) on at least the front page, it may drastically reduce load times; the lead time drainer (on our site at least) is "adsw_get_products_price_html" ajax action followed closely by "woocommerce_get_refreshed_fragments" - accounting from anything of 6-9 seconds!

Swift Performance Lite cache plugin has an option to cache ajax actions (use wisely) and our attempts with it helped shave at least 3-4 seconds off depending on when you test the page on GTMetrix - since ajax calls are dynamic - we reckon the caching of it is a hit and miss ... one time we got it down to milliseconds from 8 seconds! But there you go. Don't know what other fix there is for ajax calls - maybe just live with it.

The screenshots below show tests within minutes of each other and the time saving is about 2 seconds - we simply have Swift enabled for ajax actions as mentioned. Without those ajax calls, we expect the page (1000+ products/1.8 MB page size/72 requests) to load in no more than 2 seconds flat.

admin-ajax_GTwaterfall_06-Sep-19.pngadmin-ajax_GTwaterfall_06-Sep-19_2.png

Anyone come across a better solution to curb or at least temper ajax calls??

EDIT:
The next day ... (using the same settings):

admin-ajax_GTwaterfall_07-Sep-19_3.png

As shown above, the first line (countdown admin-ajax action) load time has been drastically reduced to milliseconds! Header reveals that caching status was HIT (not MISS) whereas the other 2 lines have a no-cache status, no expiry. But ajax calls caching are short time.

@Yaros Just wondering if the calls initiated by ADS add-ons could be delayed/deferred/omitted for the front/home page alone since most add-ons only kick in on the product or archive pages.
 
Last edited:
Top