Performance: HTTP caching headers
This affects how fast browsers load resources by controlling if and when cached files are reused instead of downloaded again.
app.use(express.static('public', { maxAge: '1d', etag: true }))
app.use(express.static('public')) // no cache headers set
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching headers | N/A | N/A | High network delay delays paint | [X] Bad |
| Cache-Control with max-age | N/A | N/A | Reduced network delay speeds paint | [OK] Good |
| No-cache forcing revalidation | N/A | N/A | Extra network round-trips delay paint | [!] OK |
| ETag with stable value | N/A | N/A | Efficient validation reduces load time | [OK] Good |
Cache-Control: max-age=3600 header instruct the browser to do?res.setHeader(name, value).res.setHeader('Cache-Control', 'no-store'), which is the correct syntax to set the no-store directive.res.setHeader('Cache-Control', 'no-cache, max-age=0');
res.end('Hello');
What will the browser do with this response?res.end('Data');
res.setHeader('Cache-Control', 'no-cache, no-store');
But the browser still caches the response. What is the likely mistake?res.end(), they won't be sent.Pass the test and this pattern moves unknown