fbpx
Want To Add Extra Images Per Product Variation For Free? Download Now

Long AJAX load with PRO

Anne Smith

I find that with PRO enable I get a very long AJAX call, if I disable PRO and just use the standard this load time reduces significantly as the AJAX doesn’t happen.

The product in question – https://colourcraft.uk/product/brusho-small-size-colours/

This is the link, it takes over 30 seconds to arrive – https://colourcraft.uk/wp-json/woo-variation-swatches/v1/single-product/115620?_locale=user and is about 128kb in size, 68 lines of AJAX.

Equally, adding to cart is dreadfully long too, presumably because it fetches this again, but I don’t know?

Please advise, this seems to be the primary cause of site speed issues. Many thanks NEIL

Hakik Zaman

Hi Anne,

Thanks for reaching out to us.

Please add the following snippet using a plugin called Code Snippets:

add_filter( 'woocommerce_ajax_variation_threshold', 'woo_variation_swatches_global_ajax_variation_threshold_min', 10, 2 );
function woo_variation_swatches_global_ajax_variation_threshold_min( $size, $product ){
return 80;
}

You can also add the above snippet inside your current theme’s functions.php file.

Note: It is recommended to add the Custom Code to the child theme’s functions.php file, to avoid any data loss while updating the Parent Theme.

Then check how it goes. Hope to hear from you soon.

Thank You

Hakik Zaman

Hi Anne,

Please revise your login details.

So that I can check the issue for you.

I have tried your login details, but it is not working- https://paste.pics/RSAHW.

Hope to hear from you soon.

Thank You

Anne Smith

Sorry about the PW, please try again now. NEIL

Hakik Zaman

Hi Anne,

Can you please point out where did you add the snippet?

I was unable to check the code as the theme editor option is hidden on your dashboard.

Also, I couldn’t find the Code Snippets plugin on your site.

Hope to hear from you soon.

Thank You

Anne Smith

Hello, it’s in “wp-themes / themes / colourcraft / inc”

in the colourcraft-template-functions.php at line 1173

regards, NEIL

Hakik Zaman

Hi NEIL,

How do I edit this file?

I need to check it by placing some other values or another snippet.

Hope to hear from you soon.

Thank You

Anne Smith

You can use the ftp as supplied. Thanks, NEIL

Hakik Zaman

Hi Anne,

Unfortunately, the FTP is not working- https://paste.pics/RSCTT

Please try to replace the previous snippet with this:

add_filter( 'woo_variation_swatches_global_ajax_variation_threshold_max', 'woo_variation_swatches_global_ajax_variation_threshold_max_edit', 10, 2 );
function woo_variation_swatches_global_ajax_variation_threshold_max_edit( $size, $product ){
return 700;
}

Then check how it goes.

Thank You

Anne Smith

Done that and product loaded. I’m away from my desk so can’t say I have comprehensively tested yet, I will respond again in a couple of hours with a more substantial report. Thank you for your assistance so far. Kind regards NEIL

Hakik Zaman

Hi NEIL,

Sure, in the meantime, please contact your hosting support.

Ask them if they have Redis Object Cache support.

If they have that support, please ask them to enable it for your site.

Our plugin is compatible with the Redis Cache. You can also use this plugin for object caching after enabling Redis Cache from the hosting support. Then enable object cache from the Redis Object Cache plugin setting.

I hope it will give you a faster experience than the present situation.

Thank You

Anne Smith

Hello,

Initial (IE cache cleared) load times are still dreadful more than 45 seconds on the original product. Most of this delay is from your AJAX call https://colourcraft.uk/wp-json/woo-variation-swatches/v1/single-product/115620?_locale=user

We have a new interesting problem – at the request of the client, I have split the product over two new products one for each weight with 34 colours. The two AJAX calls are only listing 12 in one weight and 25 in the other, do you have any idea why that would be?

Products: https://colourcraft.uk/product/brusho-individual-15g & https://colourcraft.uk/product/brusho-individual-50g

Calls: https://colourcraft.uk/wp-json/woo-variation-swatches/v1/single-product/178399?_locale=user & https://colourcraft.uk/wp-json/woo-variation-swatches/v1/single-product/178399?_locale=user

We have a dedicate cloud server running Plesk Obsidian, I cannot work out if this supports object cache, although it does have a switch per domain entitled “Caching (nginx)” which I’ve turned on. Do you know if this is the same as Redis?

I appreciate your support on this challenging matter!

Best wishes, NEIL

Anne Smith

Hello, please ignore the middle section of my last message, only the first and last paragraphs are important to me.

Specifically, slow load of (eg) https://colourcraft.uk/wp-json/woo-variation-swatches/v1/single-product/178399?_locale=user  in product:  https://colourcraft.uk/product/brusho-individual-15g

And: We have a dedicated cloud server running Plesk Obsidian, I cannot work out if this supports object cache, although it does have a switch per domain entitled “Caching (nginx)” which I’ve turned on. Do you know if this is the same as Redis?

Cheers NEIL

Hakik Zaman

Hi Anne,

It should solve adding the first snippet I gave in my previous reply.

As it is returning with Timeout, your server is not responding when API calls are initiated.

It is not an AJAX call, it is an API call. When a product has more than 30 variations, our Pro version hits your server to get the variation data. The speed depends on how fast your server responds.

There is a difference between the object cache and the normal cache. Object cache will cache your database result whereas normal cache will not.

You can try this snippet again by disabling our plugins to check the result. Is it still responding with a timeout message or not?

Hope to hear from you soon.

Thank You

Anne Smith

Hello,

Please can you explain to me the difference between:
woo_variation_swatches_global_ajax_variation_threshold_min
and
woo_variation_swatches_global_ajax_variation_threshold_max_edit
and their return values?

Many thanks NEIL

Hakik Zaman

Hi NEIL,

Those are two functions.

The First one is for the WooCommerce Default Threshold.

The Second one is for the Variation Swatches – Pro Plugin Threshold.

By default, the WooCommerce threshold is 30 and it is recommended. When a product has more than 30 variations, WooCommerce calls Ajax to get the data.

It has an issue. When a product has more than 1000 variations it takes a long time to get data (Swatches Data like- Color/Image). So, we introduce the API fetch method. Using our plugin the varations data fetched by API.

So, I gave you the first snippet to use Ajax instead of the API, but, your server couldn’t take the load and you faced a Timeout issue.

I hope the above explanation will clarify the situation.

Suggestion: You can enable the default dropdown for those products that have more than 30 variations. To do that, you can create a category and set the category here- https://paste.pics/RUEG2

Thank You

Anne Smith

Thanks, I know in the case of my more complex products, it’s the API call that is taking the time. My own APIs are near instantaneous, often with quite complex SQL, so I would very much like to explore what part of yours is not. Can you direct me to where I can investigate this in detail please? I’m aware of the exception thank you, I already utilise this for a 300+ variation product, although this is still very slow and still calls your API according to GTMetrix’ waterfall. See https://colourcraft.uk/product/acid-dye. Thank you, NEIL

Hakik Zaman

Hi NEIL,

You can check this file- woo-variation-swatches-pro > includes > class-woo-variation-swatches-pro-rest-api.php

Thank You