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

Too many Ajax requests causing high cpu

Dan Greenberg

Hi,
we are using “Variation Swatches for WooCommerce – Pro” and on the product and archive pages, it’s making a lot of ajax requests which are bringing down a pretty powerful VPS during bigger sales.
I see why this is needed, we do want to check the status and quantity of each variation swatch, while still serving a static cached version of the pages.

Can you help us figure out a way to cache(and bust on product id update or order?) those rest API requests so that at least they don’t run the whole WordPress and bring the server down?

We are using WP Rocket for caching, tried adding https://docs.wp-rocket.me/article/1523-enable-caching-for-wp-rest-api but it doesn’t seem to help, maybe because it’s a custom api endpoint. Are you aware of a way to help WP Rocket include your API endpoint in the Rest Api cache?

We tried https://wordpress.org/plugins/wp-rest-cache however the plugin is not working for some reason, not generating any caches and throwing php errors.

Thank you for your support!

Rezwan Shiblu

Hi there,

Thanks for reaching out to us. We are sorry for your inconvenience. Could you record me reproducing your issue using a tool like this? https://www.useloom.com

Can you please temporarily deactivate our Swatches plugin and check if it happens without our plugin or not?

How many variations and products you are using on your archive page?

Server requests depend on product variations and quantity. If your archive/home page has 30 products and each product has 5 variations so 30*5 = 150 server requests.

In our latest version, we cache the data for 1 hour and if a visitor hit the URL it will hit your server once, then data will be cached and data will be served from the locale.

Please reduce the product number on the first load.

Basically, we suggest 15 products on the first load, then use infinite scroll to load more products.

Thank You

Dan Greenberg

Hi Alex,
thank you for your detailed response, I appreciate it.

Since our shop is relatively big and during the holiday season the traffic is substantial, we are looking for a more bulletproof solution, not just reducing things down, hiding products behind more ajax requests, and hoping it will be enough(while if the marketing double the traffic – it just won’t be…)

WP Rocket is probably the best and most popular premium caching solution and what we will try to do, is make it work with your plugin’s AJAX requests. This way, we can have 15 or 1500 such requests –  a static response will be returned to the user without booting up the whole wordpress, and that static response will be cached not only for a specific duration of time, but also until the product ID is either updated or sold.

Can you or your engineers help us identify how we can help WP Rocket do that job?
It’s quite a flexible plugin full of actions and filters and there are 3rd party integrations with all the major plugins on the market.

Hope this makes sense, and thanks again for the support

Rezwan Shiblu

Hi there,

Every request needs time for completing the full process. If you send 500/1000/1500 requests then no caching plugin or tool will not help.

From our end, we cache the data for 1 hour and if a visitor hit the URL it will hit your server once.

So the only solution is to reduce your product per load.

Thank you.