-
Notifications
You must be signed in to change notification settings - Fork 26
Description
This is a stub/meta issue for tracking work to leverage Service Workers (SW) as a fallback on public gateways.
cc historical SW threads for discovery: #57 #171 #158 ipfs/kubo#4025 #55
Broad strokes idea
- SW would intercept requests for specific content root (
/ipfs/cid/or/ipns/id) and load data using- Helia
- delegated routing over HTTPs (caskadht from cid.contact,
/routing/v1/providers/cid?cascade=ipfs-dht) - bitswap over WebTransport transport (allowing direct fetch from Kubo)
Prior art
There are two ways one can fetch blocks:
- Demo on js.ipfs.tech uses ancient js-ipfs not sure if it still works. But we could redo that with Helia, IPNI and WebTransport.
- Saturn' browser client uses ?format=car instead, and fetches it from a single public gateway. Unsure if good prior art to look at tho.
I think the thing we want to create something robust that does do both, and use all public gateways as a fallback
Open questions
When SW is registered / used
First HTTP GET will always hit the gateway. Response could register worker and reload.
Future requests will hit SW, as long they come from the same Origin (see "no foreign fetch" below)
No foreign fetch
tldr: this means SW is active only if the root document loaded in the browser comes from the same Origin.
Use case ideas
(A) Client-side recovery
When gateway returns error (list tbd, could be 429 and maybe also 502 503 and 504), and it knows request comes from web browser, return text/html response (ipfs/boxo#262).
Augument text/html response to include an option to recover from page load error via a Service Worker IPFS node.
This is a good candidate for dipping our toes, does not impact "successful" flow, but allows for recovery from 429 Too Many Requests and Saturn CDN hiccups we will see in the near future.
Recovery could be based on Helia and WebTransport and/or verifiable HTTP block/car requests to public gateways
(B) Ability to register global worker
Giving user ability to prefer local JS for future requests, not only for errors, but all responses.
(C) Ability to isolate path gateway
We could do something related to #157 where actual payload is loaded in sandboxed iframe