Hi Chris,
If the link is to the exact same page, then no it won’t prerender the page again but is smart enough to recognise this as the same.
If it has different query params, then it will treat those as different pages as it can’t know whether the page is the same or different. If those query params aren’t important to the rendering of the page (e.g. UTM pages), then we are working on ways for sites owners to let the browser know those query params don’t matter and can be treated as the same page (this already is available for prefetch but not for prerender).
Speculation Rules will also keep up to two prerendered links in memory at a time, to reduce the memory impact of this feature.
So, if you hover over link1, then link2, then link3, then link1 again it will prerender links 1, then 1+2, then 2+3 (evicting link 1), then re-prerender link 3 (evicting link 2) so you have links 2+3 prerendered.
But, even with this, there’s a few things to keep in mind:
- The user must hover over a link for 200ms so just randomly scanning past a link will not initiate the prerender.
- If you have concerns about this, then you can change the setting from the default “moderate” eagerness setting to “conservative” so prerendering only triggers on mouse/pointer down. This will trigger a lot less, but at the cost of having a smaller lead time (so not as much performance gain as the page may not be fully prerendered by the time the user finishes the “click” and navigates to the page). See this recent tweet.
- If still concerned then can also choose prefetch over prerender. However, with WordPress sites without HTTP Caching (that I’ll cover next) this is often nearly as costly as a full prerender.
- Speculation Rules will make use of the HTTP cache. So if you prerender link1 then any cacheable resources (with cache-control headers) will be stored in the HTTP cache. Then if you prerender link1 a second time, the resources can be read from the cache and the cost to prerender the second time is much reduced (basically memory and CPU costs but no—or at least much reduced—network and server costs). A word of warning here is that many sites (including many WordPress sites) set the HTML to be uncacheable so you may have to refetch the document in this case. ?? It’s recommended to set even a small cache time for performance anyway and that would avoid this.
Hope that answers all your questions here but let us know if you have any more questions.
We’ve thought long and hard about trying to reduce the cost of speculation as much as possible and make this feature as easy as possible for most sites to use without having to be too concerned about that.