Use page endpoints' headers
if load function isn't present in page
#5218
Labels
headers
if load function isn't present in page
#5218
Describe the problem
Currently, returning a
headers
value from page endpoints doesn't change the page's HTML response headers. For example, if you want to pass a "Cache-Control" header to cache your pages, you must either:load
function'scache
output, which doesn't supports-max-age
orstale-while-revalidate
and requires adding the load function that wouldn't otherwise be needed. This defeats page endpoints' purpose of removing boilerplate.handle
hook that sets cache headers for all pages based on their URL. This is limited in that headers can't access the props passed by page endpoints to determine truly dynamic header values (such as setting a higher cache duration on long-published content)Describe the proposed solution
When pages don't have a
load
function, it'd be ideal if they inherited theheaders
from their corresponding page endpoint. Perhaps we should make it so even when the load function exists (unless it overwrites headers) as it'd make documentation simpler and more straightforward.Alternatives considered
Another possible solution is to allow the handle hook to access data from page endpoints in the response value of
resolve(event)
.Importance
would make my life easier
Additional Information
I'm learning about cache-control headers and am not an expert on HTTP in general (learning about the platform with SvelteKit!), so I may be overlooking something.
I'm a bit frustrated that I thought my website was being cached for the 6 months it's been live, when actually I was only caching the endpoint data, not the full page. And I'm not even sure what's the impact of caching the endpoint data as I don't think they're called by themselves.
In general, this whole data fetching process feels very confusing and I'm afraid page endpoints made it even more so 😔
The text was updated successfully, but these errors were encountered: