Q29: How do `req.fresh` and `req.stale` support HTTP Caching?

Difficulty:MediumTopic:Performance
  • req.fresh: Returns true if client conditional cache headers (If-None-Match, If-Modified-Since) match current response headers, indicating the client's cache is fresh.
  • req.stale: Inverse of req.fresh. Returns true if client cached data is stale, indicating updated data must be transmitted.
Key Takeaways
  • If req.fresh is true, respond with res.status(304).end() to save network bandwidth.
  • Helps automate HTTP/1.1 cache validation responses.