The only cache in Speculative Loading is the browser cache. It holds onto prerendered/prefetched pages just for a maximum of 5 minutes (in Chrome). So there is no cache to clear.
That’s not strictly true Weston.
Speculation Rules basically uses the memory cache, so it can also be used for resources that aren’t cacheable in the HTTP Cache. As I often say it’s like right clicking a link and opening it in a new tab but not switching until later. In that case you wouldn’t expect the other tab the user opened to be closed when state changes and that doesn’t happen for Speculation Rules pages either.
However, it will only live for the duration the user is on the page (unless it’s saved in the HTTP Cache too as usual) so there is no long term cache.
To cancel a speculation you need to move to another page, or remove the speculation JSON from the page (which needs to be done through JavaScript and is not something the plugin can do since it doesn’t know what triggers that removal need).
However, it seems the OP has a longer term issue here so seems like it’s completely separate to speculation rules maybe?
Thread Starter
CamZL1
(@danishhaidri)
Hi Guys, thank you for the quick reply.
(please let me know if I should create a new string for this for other users)
Will this plugin effect Logged in users? Can an exclusion be made for logged in users? At the moment we have Cloudflare + LiteSpeed Cache + SL (trial). We dont want logged in users seeing outdated content specially those who perhaps visited a page and did not close their browser and continued browsing the next day. (hypothetical scenario)
-
This reply was modified 1 year, 7 months ago by
CamZL1.
Barry can speak to the specifics of how likely the prerendered content will persist (e.g. into the next day).
We have an issue open to consider disabling speculation rules from being added by default when a user is logged-in: https://github.com/WordPress/performance/issues/1157
For now if you want to prevent speculation rules from being printed on the page for logged-in users, you can use the following plugin code:
<?php
add_action( 'init', static function () {
if ( is_user_logged_in() ) {
remove_action( 'wp_footer', 'plsr_print_speculation_rules' );
}
} );
-
This reply was modified 1 year, 7 months ago by
Weston Ruter.
If a page is backgrounded (e.g. switching tabs) for more than 3 mins it cancels the speculations. Would need to test whether locking the computer counts as it being backgrounded.
Thread Starter
CamZL1
(@danishhaidri)
@westonruter thank you for sharing the PHP. It has been added.
@tunetheweb please do let me know how the test goes.
Thank you both.
For prefetch, it follows Chrome’s 5 minute timeout, so your next day issue shouldn’t be a concern.
For prerender, there is no timeout as long as the page is in the foreground. And sleeping the computer does not count as backgrounding. I’ve raised this issue to see if we should improve this: https://issues.chromium.org/issues/335924597
For now, if you have those specific concerns, prefetch may be the better option for you. It won’t quite be an instant navigation, but should still provide a good headstart anyway.