eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Add support for Speculation Rules

Open tunetheweb opened this issue 1 month ago • 8 comments

Is your feature request related to a problem? Please describe.

Chrome has recently launched the Speculation Rules API which provides a way of a page telling the browser to prefetch or prerender a future navigation with a simple JSON-based objected added to the page (or referred to from an HTTP Header), which either lists the list of URLs, or gives details of hrefs patterns or CSS selector matches to find links on the page. I recently presented on this at Google I/O 2024, which provides a good summary for those willing to sit through my jammering on about it for 30mins.

Speculation Rules is for full page, browser-controlled, navigations (some people use the "MPA" term, but I like to call them "webpages" 🙂), which means they are ideally suited for SSG sites using things like 11ty!

While SSG sites often are fast by default, faster perf is always a good thing IMHO, as long as the balance between effort versus reward makes it worthwhile—which we believe it is for this API.

Describe the solution you'd like

I'm wondering what opportunities there are to more fully integrate this into 11ty?

  • Could there be a default Speculation Ruleset that's easily enabled with a config option? Or should it be enabled by default with an option to disable it?
  • Should we expose an API to set a speculation rule (either to add/remove from a default or to set it?).
  • Should 11ty apply additional heuristics beyond those exposed by the API (which currently is basically speculate immediately, on hover, or on pointerdown)?
  • Something else?

I realise this is a fairly open ended question, but keen to hear the community's thoughts on this. I'm more than willing to answer any questions, and even help with any implementation here.

Describe alternatives you've considered

I did consider a plugin for this, and had a look and discovered that a plugin already exists. Maybe that's sufficient and we don't need to do anything further here? Or maybe implementing this in the main 11ty codebase/repo would be better if we think this would have high value for 11ty users?

Additional context

As a similar use case, we created a WordPress plugin for that platform and it has been received very positively. We're also considering proposing adding this to WordPress core if the plugin proves successful. We're willing (and in fact keen!) to work with other platforms where this API would potentially add a lot of value.

tunetheweb avatar May 23 '24 15:05 tunetheweb