#Cache result of fetch in loader

1 messages · Page 1 of 1 (latest)

wise jackal
#

I have a fetch() that is taking >500ms every loader run. I'd like to cache it more heavily so that the user doesn't sit wondering if their click/tap worked.

Alternatively I suppose I could move the logic to the browser (clientLoader?) but I wanted to investigate caching first.

export async function loader() {
  const response = await fetch(`https://getdata.com/${coolId}`, { headers: Authorization })
quaint plover
waxen ledge
#

Do you have a CDN? Try setting cache-control: s-maxage=<seconds> which would cache the page in the CDN

quaint plover
ashen canopy
wise jackal
#

I guess I'm confused because I've been spoiled with easy cache setting headings with Sanity/Shopify and I thought I would be able to give server-side fetch a cache header setting and voila

ashen canopy
#

Nah, that's not how server-side fetches work. If you want a server-side cache, you'll need to use something like cachified.