Complete the code to set a cache control header for 1 hour in Remix loader.
export const loader = async () => {
return new Response('data', {
headers: { 'Cache-Control': '[1]' }
});
};The Cache-Control header with public, max-age=3600 tells browsers and proxies to cache the response for 3600 seconds (1 hour).
Complete the Remix loader code to set a stale-while-revalidate directive for 30 seconds.
export const loader = async () => {
return new Response('content', {
headers: { 'Cache-Control': 'public, max-age=60, [1]=30' }
});
};stale-while-revalidate=30 allows the cached response to be used while the browser fetches a fresh copy in the background for 30 seconds.
Fix the error in the Remix loader to properly set a no-store cache policy.
export const loader = async () => {
return new Response('no cache', {
headers: { 'Cache-Control': '[1]' }
});
};no-store tells browsers and proxies not to cache the response at all, ensuring fresh data every time.
Fill both blanks to create a Remix loader that caches publicly for 5 minutes and allows stale content while revalidating for 10 seconds.
export const loader = async () => {
return new Response('cached data', {
headers: { 'Cache-Control': 'public, max-age=[1], [2]=10' }
});
};max-age=300 caches for 5 minutes (300 seconds), and stale-while-revalidate=10 allows using stale content for 10 seconds while fetching fresh data.
Fill all three blanks to create a Remix loader that caches privately for 2 minutes and disables transformation.
export const loader = async () => {
return new Response('private cache', {
headers: { 'Cache-Control': '[1], max-age=[2], [3]' }
});
};private caches only in the browser, max-age=120 caches for 2 minutes, and no-transform prevents proxies from modifying the response.