Cacheable Requests for Remote Content
TLDR: proxyUrl requests are un-cacheable, this is a terrible Developer Experience.
When fetching remote Activities, Objects or Actors with the ActivityPub API we use a few endpoints. First, we might fetch activities directly from our Inbox endpoint, this loosely translates to a users Home feed.
But to represent these Activities in a meaningful way to users, we also need information about the Actor who posted the activity, so that we may display their Avatar, Display name and perhaps their Webfinger1.
We could fetch an Actor directly from a client, but not all ActivityPub servers are guaranteed to have CORS enabled. So to reliably fetch, we use the proxyUrl endpoint2.
… the client posts an x-www-form-urlencoded id parameter with the value being the id of the requested ActivityStreams object.
Unfortunately POST requests are opaque regarding the id3.
Typically, a Service Worker would use a fetch eventListener to intercept the request, and depending on cacheing strategy might first look up this id in the cache, or indexedDB, and if it isn’t found would then fetch and save response for later use.
So back to our Home feed, when scrolling through the activities you are likely to see a number of posts from the same people, whether because you only follow a few or because you follow some frequent posters.
Without cacheing, our app would need to fetch those Actors again and again, each time one of their posts shows up. Also, depending on your server configuration, could get your client rate-limited.
Beyond ActivityPub, not cacheing is wasteful, these continuous requests could not only make a low-powered device slow-down, heat up and drain a mobile battery, but depending on internet access where you live could also eat into your data plan.
- Webfinger is an identifier & protocol for looking up information about users, which should look familiar:
user@example.com ↩︎ - https://www.w3.org/wiki/ActivityPub/Primer/proxyUrl_endpoint ↩︎
- Basically a URL: https://www.w3.org/TR/activitypub/#obj-id ↩︎
#activitypub #c2s #UX