Knowledge
Caching a Breakdance WooCommerce shop: what to cache and what not
You can cache a Breakdance WooCommerce shop just fine, as long as the cart, checkout and my-account stay out of the cache and the cache is cleared on stock and price changes. The rest of the shop, such as product pages and categories, benefits a lot. Breakdance itself changes nothing here: WooCommerce still decides what is personal. Below are the points where it goes wrong.
In short
- Always keep the cart, checkout, my-account and add-to-cart URLs out of the page cache.
- Cart fragments (wc-ajax=get_refreshed_fragments) are a separate request. You can turn them off on pages without a cart element.
- A change in stock or price must clear the product page, categories and shop.
- Filter URLs with parameters are best cached only when the filter plugin says it is safe.
- With multiple currencies or geolocation you need a cookie exclusion, otherwise everyone sees the same price.
Which pages must stay out of the cache?
WooCommerce marks its own cart, checkout and account pages with DONOTCACHEPAGE, and Spark Speed respects that, also for renamed or translated slugs. On top of that there is a list of URL parts that are never stored, such as cart, checkout, my-account, wc-api and add-to-cart. The Woo preset adds Dutch variants: winkelmand, afrekenen, mijn-account and order-received. Note that such a list matches part of the URL: a page with cart in its slug stays out of the cache too.
What are cart fragments and should you turn them off?
Cart fragments are the AJAX request WooCommerce makes on every page to refresh the cart icon in the header. On a Breakdance site with a mini cart in the header that request is useful; on pages without a cart element it is wasted effort. Spark Speed has an optional 'optimized' mode that removes the wc-cart-fragments script everywhere except on cart, checkout, account, product pages, shop and product categories. The mode is off by default. The response of that request itself is not cached.
May a customer with a filled cart see the cache?
By default a visitor with items in the cart gets a fresh page every time. That is safe but not fast. Spark Speed can speed this up (woo_cart_cache), but only if you switch it on after a check on your own site: it adds a real product to a cart, renders the pages anonymously and with the cart, and compares them. Only on an equal result, or a difference you approved, does it turn on. The check runs again every week. A page that contains a cart notice is never stored in the shared cache.
When must the cache be cleared for stock and price?
A sold-out product that still looks available in the cache disappoints customers. Spark Speed listens to the WooCommerce stock hooks, also for changes through REST, import or scheduled actions. A quantity change only counts if the shop shows that quantity. All products in one request are handled together, and variations point to the parent product. Then the product, its categories, the archive, the blog page and the home page are dropped from the cache.
What about filters and multiple currencies?
WooCommerce filters (filter_, orderby, min_price) are not cached by default, so those pages render every time. A filter plugin can state itself that a URL is safe. That is a trade-off: safe, but less fast. If you use a currency plugin or geolocation, there is no separate cache variant per currency. Add the currency cookie to the excluded cookies, which means those visitors are not served from the cache.
After setting up, put a test product in your cart and click through to a product page. If you do not see your item, or see someone else's notice, the exclusion is wrong.
Spark Speed keeps cart and checkout out of the cache and clears product pages on stock changes.
Frequently asked questions
No. The cart, checkout and my-account differ per customer and do not belong in a shared cache.
Because by default they get a fresh page. That is deliberately safe. The cart cache option is a choice made after a check.
No, that happens automatically with Spark Speed. A change through REST or import is picked up too.