web-platform-tests / interop

web-platform-tests Interop project
https://wpt.fyi/interop
309 stars 28 forks source link

Speculation Rules API #754

Open BearCooder opened 3 weeks ago

BearCooder commented 3 weeks ago

Description

The Speculation Rules API is designed to improve performance for future navigations. It targets document URLs rather than specific resource files, and so makes sense for multi-page applications (MPAs) rather than single-page applications (SPAs).

The Speculation Rules API provides an alternative to the widely-available feature. It provides many improvements over these technologies, along with a more expressive, configurable syntax for specifying which documents should be prefetched or prerendered.

Specification

https://wicg.github.io/nav-speculation/speculation-rules.html

Additional Signals

Webkit: https://github.com/WebKit/standards-positions/issues/54 Mozilla: https://github.com/mozilla/standards-positions/issues/620

Tests: https://wpt.fyi/results/speculation-rules?label=master&label=experimental&aligned&q=speculation

Info about:

domenic commented 2 weeks ago

Oh, very cool to see this posted.

As one of the spec maintainers and Chromium engineers on this feature, I think it's important to emphasize that speculation rules is a surface API that triggers (as of now) two larger features: prefetching, or prerendering. Those are specified in https://wicg.github.io/nav-speculation/prefetch.html and https://wicg.github.io/nav-speculation/prerendering.html. So just implementing the speculation rules spec by itself doesn't help; you'd need to implement one or both of those.

If the parties involved don't want to accept everything into Interop 2025, I think accepting speculation rules + prefetching (omitting prerendering) would be a good compromise. As of October 1, speculation rules prefetch is used on ~12% of page loads, and this number is likely to go up a good chunk more as Cloudflare's Speed Brain deployment continues. Speculation rules prerender, although it's more dramatic and certainly well-loved among web developers, isn't seeing as-high adoption numbers. And working prefetch this year would be good groundwork if browsers wanted to tackle prerender the next year.

ryantownsend commented 2 weeks ago

@domenic I agree prefetch-only is a really good compromise on scope but one thought on this: would it be wise for them to treat prerender rules asif they were declared as prefetch?

In my view, prerender is a stronger signal that a URL/href will be the next page (I know we have eagerness for that too) so they could depend on effectively downgrading prerender where it's not supported.

If browsers weren't to do this, then we'll end up having to conditionally serve Speculation Rules to different browsers (possibly needing UA sniffing?), which is far from ideal.

domenic commented 1 week ago

I agree that treating prerender as prefetch is reasonable. We've thought of doing that at times in Chromium (e.g. if limits are hit), but haven't as of yet.