Svelte · Middle · Question 69 of 75

How do you set cache headers for a page from load?

export async function load({ fetch, setHeaders }) {
  const res = await fetch("/api/products");
  setHeaders({ "cache-control": res.headers.get("cache-control") });
  return { products: await res.json() };
}

Explanation

Each header can be set only once. setHeaders has no effect when load runs in the browser.

Further reading

Problem with a question

Svelte · Middle · question 69

Test yourself

Take the Svelte · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz