Consider an Express server that sets the header Cache-Control: no-store on responses. What will happen when a browser receives this header?
app.get('/data', (req, res) => { res.set('Cache-Control', 'no-store'); res.send('Fresh data'); });
Think about what no-store means for caching.
Cache-Control: no-store tells browsers not to store any part of the response. This means the browser will always fetch fresh data and never use a cached copy.
Which code snippet correctly sets a strong ETag header with value "12345" on the response?
Strong ETags do not start with W/.
A strong ETag is a quoted string without the W/ prefix. Option B sets ETag to "12345" correctly. Option B sets a weak ETag. Option B uses lowercase header name which Express normalizes but lacks quotes. Option B is missing quotes and uses lowercase header name.
An Express server sends ETag: "abc123". The client sends a request with header If-None-Match: "abc123". What status code will the server respond with if it uses res.status(304).end() on match?
app.get('/resource', (req, res) => { const etag = '"abc123"'; res.set('ETag', etag); if (req.headers['if-none-match'] === etag) { res.status(304).end(); } else { res.send('Resource content'); } });
What does status 304 mean in HTTP?
Status 304 means the resource has not changed. The server tells the client to use its cached copy without sending the body again.
Given this Express code, why might the browser still cache responses despite setting Cache-Control: no-cache?
app.get('/info', (req, res) => { res.set('Cache-Control', 'no-cache'); res.send('Info data'); });
Check the meaning of no-cache in HTTP caching.
Cache-Control: no-cache means the browser can store the response but must check with the server before using it. It does not prevent caching entirely.
Which statement best describes how Express generates ETags for responses by default?
Check Express documentation on default ETag behavior.
Express generates weak ETags by default. It uses a hash of the response body to create a weak ETag, which starts with W/. This helps with caching but allows some flexibility in content changes.