Speculation Rules | Clear prefetch & prerender cache after cart item action #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using Speculation Rules, you may run into the issue of serving stale content.
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
$responseobject:checkout_cart_add_product_completecheckout_cart_update_item_completeThe 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.