Site logo

Archived topic

Ajaxify cart viewer for cache compatibility

5 replies · Started by Joachim on January 19, 2022

Viewing posts 1–6 of 6

Hi there,

Is there a way to ajaxify the cart viewer so that shop pages can be fully cached whether there are items in the cart or not and have the cart content loaded asynchronously?
Our current caching system works nicely for anonymous visitors but we have to bypass the page cache as soon as an item is added to cart, making the website much slower.

Hi there,

do you mean the GP Menu Cart ? If so that is already using Ajax. Let me know.

Yes, the menu cart... But if I have an item in the cart and refresh the page with JS disabled, I'm still seeing how many items are in the cart.
So I guess the cart content is immediately rendered "inside the page/template" and not loaded with ajax.
The behavior at http://gpsites.co/seller/ is similar.

Here's an example of a working ajax cart viewer where the cart content is loaded dynamically, allowing the page to be cached: https://savoy.nordicmade.com

Hi there,

Not sure I'm fully understanding here. Our menu cart uses the built-in AJAX cart functionality found in WooCommerce.

Is there something specific I can do on our Seller site to see the issue you're having?

Hi Tom :)

We're looking for a way to have the content of the menu cart only getting loaded via AJAX so that we can serve the same fully cached page to all visitors.
In case they have previously added something to the cart, that would be loaded via AJAX while the initial HTML content of the page would not have anything in the cart.

If you try the following on both the Seller and Savoy sites, you can see the difference.
1. Add any product to the cart.
2. Disable JavaScript in your browser.
3. Go to another page of the demo site or refresh the page.

In Seller, you will see that there's an item in the cart, meaning that this will be a problem if this page is cached and served to all visitors.
In Savoy, you will not see the cart content since it is fully loaded via AJAX and requires JS. This also means that the page can be cached and served to all visitors. The cart content will be loaded asynchronously.

Ah, I understand.

This would likely require completely rebuilding the feature using a custom solution, as the default WooCommerce cart widget isn't fully AJAX-based.

Perhaps a plugin like this will do the trick?: https://wordpress.org/plugins/side-cart-woocommerce/

This archived topic is closed to new replies.