Skip to content

Can I set headers on deferred responses? #7807

Closed Answered by tammo
tammo asked this question in Q&A
Discussion options

You must be logged in to vote

Alright I am stupid.. I was so focused on the "deferred response", that I missed that the loader can set headers as well. So to get it right: the loader function is responsible for the _data body and headers.

And to answer my own question:
Setup cache headers via the loader function defer({ meteorites }, { headers });
As well as read the loader cache-control headers in the route module. Because to quote the docs "Usually your data is a better indicator of your cache duration than your route module"

export function headers({ loaderHeaders }: HeadersArgs) {
  return {
    "Cache-Control": loaderHeaders.get("Cache-Control"),
  };
}

What also helped me was this article about prefetching: http…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@EfosaE
Comment options

Answer selected by tammo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants