Skip to content

Conversation

@FinnReinhardtBsc
Copy link

When using Speculation Rules, you may run into the issue of serving stale content.

  • A user clicks on a product
  • They trigger a speculative load (let's say a prefetch) on a familiar product or link
  • They add the product to their cart
  • When they navigate to the prefetched site, they will be served stale content from the prefetch cache

The Clear-Site-Data header can be used to clear the prefetch and prerender cache, which is used by the Speculation Rules API (see MDN documentation). This ensures, that previous speculative loads will be discarded, so the user will not be served stale content.

I have added an observer for the following events, which include the $response object:

  • checkout_cart_add_product_complete
  • checkout_cart_update_item_complete

The resulting header will look like this:
Clear-Site-Data "prefetchCache", "prerenderCache"

ℹ️ I am not sure if this problem persists when adding a product to the cart or updating the quantity triggers a reload. This is primarily concerning AJAX calls.

@rhoerr
Copy link
Contributor

rhoerr commented Nov 1, 2025

Thank you for the contribution and PR. Based on the discussion in #20 and the prerenderCache value being not broadly supported yet, I've opted to merge #24 instead.

@rhoerr rhoerr closed this Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants