Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Make the Mini Cart block cache-friendly #9353

Closed
Tracked by #9198
Aljullu opened this issue May 4, 2023 · 1 comment · Fixed by #9493
Closed
Tracked by #9198

Make the Mini Cart block cache-friendly #9353

Aljullu opened this issue May 4, 2023 · 1 comment · Fixed by #9493
Assignees
Labels
block: mini-cart Issues related to the Mini-Cart block. type: enhancement The issue is a request for an enhancement.

Comments

@Aljullu
Copy link
Contributor

Aljullu commented May 4, 2023

Currently, if a store wants to use page caching, the Mini Cart block can show outdated totals or even totals from other sessions. We would like to fix that so stores can enable page caching without problems even when having the Mini Cart block in their page.

See also #7530.

To reproduce

  1. Install WP-Optimize - Clean, Compress, Cache or a similar caching plugin.
  2. Go to WP-Optimize > Settings > Cache and enable page caching.
  3. In the frontend without being logged in (ie: in a private/incognito window) visit any page.
  4. Add some products to your cart.
  5. Visit the same page from step 3.
  6. Notice the Mini Cart totals don't include the products you added in step 4.

Expected behavior

Mini Cart should always show the correct totals, even if caching is enabled.

Approach

In order to solve that, we would like to:

  1. Store cart data in the client local storage. Ideally we would store the minimum data needed for the Mini Cart to show the correct values.
  2. On PHP render, we would render the Mini Cart block as we do right now, assuming there are 0 products in the cart.
  3. On page load:
    3.1. We would check if the user has some cart data in their local storage. If it does, we will use it to fill Mini Cart block details.
    3.2. In addition to the previous step, we will make a query to the Store API to gather the cart values and will update them in the Mini Cart button. We will save these values into the user local storage.
@Aljullu Aljullu added type: enhancement The issue is a request for an enhancement. block: mini-cart Issues related to the Mini-Cart block. labels May 4, 2023
@Aljullu Aljullu changed the title Investigate making the Mini Cart block cache-friendly Make the Mini Cart block cache-friendly May 4, 2023
@bitmakers
Copy link

I was about to post a related issue but just found this - making the cart totals update on cached pages is essential in my opinion, especially since the mini cart block will likely be included in the header on every page.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants