Closed Bug 2001151 Opened 10 months ago Closed 1 month ago

[Spike] Prototype Speculation Rules prefetch (proof-of-concept)

Categories

(Core :: Networking, task, P3)

task

Tracking

()

RESOLVED FIXED

People

(Reporter: acreskey, Assigned: acreskey)

References

(Blocks 1 open bug)

Details

(Whiteboard: [necko-triaged])

Attachments

(4 obsolete files)

It could be useful to understand scope and potential bottlenecks to build a minimal, non-compliant, proof-of-concept of Speculation Rules, prefetch.

  • Not production code, just for investigating implications *
Assignee: nobody → acreskey
Attachment #9530071 - Attachment description: WIP: Bug 2001151 - [Spike] Prototype Speculation Rules prefetch (proof-of-concept) → Bug 2001151 - [Spike] Prototype Speculation Rules prefetch (proof-of-concept)
Attachment #9530071 - Attachment description: Bug 2001151 - [Spike] Prototype Speculation Rules prefetch (proof-of-concept) → WIP: Bug 2001151 - [Spike] Prototype Speculation Rules prefetch (proof-of-concept)

The attached patch implements a proof-of-concept for Speculation Rules prefetch functionality.

Disclaimer: This code was almost entirely generated by Claude from my instructions and is for investigative proof-of-concept purposes only; it has not been fully reviewed or tested and should not be used in production.

Notes:
• Add SpeculationRulesParser to parse speculation rules JSON
• Parses speculation rules from: inline scripts, dynamically added scripts, external JSON files, and HTTP Speculation-Rules response headers
• Implement prefetch action with eagerness levels:
immediate: Prefetch as soon as rules are parsed
eager: (not yet implemented)
moderate: Prefetch on mouse hover over matching links
conservative: Prefetch on mousedown on matching links
• Prerender action is mapped to prefetch
• Add prefetchURIForSpeculationRules() to bypass must-revalidate directives (not working for all requests)
• Use cache metadata to mark speculation-rules prefetches, cleared after first use
• Cache entries valid for 5 minutes via ForceValidFor(300)
• Add prefs: dom.speculation_rules.enabled and dom.speculation_rules.prefetch_on_mousedown

It's easiest to observe the behavior through the web console (currently quite verbose)

I'm testing this on a series of simple tests that I'm hosting here: https://acreskeymoz.github.io/speculation_rules/prefetch/

This is working quite well on some production sites like scalemates.com
https://www.scalemates.com/

And it's partially working on the deployed-at-scale Shopify speculation rules.
e.g. this rule: https://jeffreestarcosmetics.com/cdn/shopifycloud/storefront/assets/storefront/storefronts.specrules-dd5621a1.json
seen here: https://jeffreestarcosmetics.com/
The rules (provided in the header response) will be loaded and the runtime will preload the link target (e.g. a collection) based on the conservative mouse down action. However on the subsequent load the document is still fetched over the wire. To be investigated.

Attachment #9530836 - Attachment is obsolete: true
Attachment #9530071 - Attachment is obsolete: true

It's just a simple test case, but bug 2007155 is showing that the POC and the HTTP cache is working well so far.

Attachment #9539410 - Attachment is obsolete: true
Attachment #9539409 - Attachment is obsolete: true

Was prototyped, portions of which were landed, but this bug is no longer needed as we are landing the full impl in bug 1969396

Status: NEW → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: