0
0
Expressframework~20 mins

HTTP caching headers (ETag, Cache-Control) in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
HTTP Caching Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the effect of setting Cache-Control: no-store in Express?

Consider an Express server that sets the header Cache-Control: no-store on responses. What will happen when a browser receives this header?

Express
app.get('/data', (req, res) => {
  res.set('Cache-Control', 'no-store');
  res.send('Fresh data');
});
AThe browser will never cache the response and will always request fresh data.
BThe browser will cache the response but revalidate it before each use.
CThe browser will cache the response and use it without revalidation until it expires.
DThe browser will cache the response only if the ETag matches.
Attempts:
2 left
💡 Hint

Think about what no-store means for caching.

📝 Syntax
intermediate
2:00remaining
Which Express code correctly sets an ETag header?

Which code snippet correctly sets a strong ETag header with value "12345" on the response?

Ares.header('etag', 'W/12345');
Bres.set('ETag', '"12345"');
Cres.set('ETag', 'W/"12345"');
Dres.setHeader('etag', '12345');
Attempts:
2 left
💡 Hint

Strong ETags do not start with W/.

state_output
advanced
2:00remaining
What is the response status when If-None-Match matches ETag?

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?

Express
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');
  }
});
A200 OK with resource content
B500 Internal Server Error
C404 Not Found
D304 Not Modified with no body
Attempts:
2 left
💡 Hint

What does status 304 mean in HTTP?

🔧 Debug
advanced
2:00remaining
Why does this Express code not cache responses as expected?

Given this Express code, why might the browser still cache responses despite setting Cache-Control: no-cache?

Express
app.get('/info', (req, res) => {
  res.set('Cache-Control', 'no-cache');
  res.send('Info data');
});
ABecause <code>no-cache</code> means the browser must revalidate but can cache the response.
BBecause <code>no-cache</code> disables caching completely.
CBecause the server forgot to set <code>ETag</code> header.
DBecause <code>Cache-Control</code> header is ignored by browsers.
Attempts:
2 left
💡 Hint

Check the meaning of no-cache in HTTP caching.

🧠 Conceptual
expert
2:00remaining
How does Express handle ETag generation by default?

Which statement best describes how Express generates ETags for responses by default?

AExpress automatically generates strong ETags based on response body content using a hash function.
BExpress disables ETag generation by default; developers must set them manually.
CExpress generates weak ETags by default using a hash of the response body.
DExpress generates weak ETags by default using response content length and modification time.
Attempts:
2 left
💡 Hint

Check Express documentation on default ETag behavior.