Performance: Cache headers for performance
Cache headers affect how fast the browser loads resources by controlling if and when files are reused from local storage instead of downloaded again.
export const loader = () => {
return new Response('data', {
headers: {
'Cache-Control': 'public, max-age=31536000, immutable'
}
});
};export const loader = () => {
return new Response('data', {
headers: {
'Cache-Control': 'no-cache'
}
});
};| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching (Cache-Control: no-cache) | N/A | N/A | High network delay causes slower paint | [X] Bad |
| Proper caching (Cache-Control: public, max-age=31536000, immutable) | N/A | N/A | Fast paint due to no network delay | [OK] Good |
Cache-Control headers in a Remix app?Cache-ControlCache-Control header specifically controls caching duration and behavior.headers that returns an object with headers.headers returning the header object.Cache-Control header value sent to the browser?
export function headers() {
return { 'Cache-Control': 'public, max-age=600' };
}export const headers = {
'Cache-Control': 'max-age=1200'
};
What is the problem?headers export to be a function returning headers, not a plain object.Pass the test and this pattern moves unknown