Express req.fresh Property
What you’ll learn
- What
req.freshmeans in conditional HTTP requests. - How ETag and Last-Modified influence freshness.
- How to return efficient
304 Not Modifiedresponses. - How
req.freshcompares withreq.stale.
Usage syntax
javascript
req.fresh
req.stale1
Send 304 when request is fresh
javascript
app.get('/news', function (req, res) {
res.set('ETag', '"news-v1"');
if (req.fresh) return res.status(304).end();
res.json({ items: ['a', 'b', 'c'] });
});2
Use Last-Modified with freshness checks
javascript
app.get('/article', function (req, res) {
res.set('Last-Modified', new Date('2026-05-01').toUTCString());
if (req.fresh) return res.status(304).end();
res.send('Latest article content');
});❓ FAQ
It indicates whether the client's cached representation is still fresh according to HTTP validators.
It is based on conditional request headers like If-None-Match and If-Modified-Since and your response validators.
Use req.stale, which is true when the cache is not valid and content should be sent again.
Yes. It is useful for efficient GET endpoints that support ETag or Last-Modified caching.
You can rely on Express defaults or set validators explicitly for predictable cache behavior.
Did you know?
req.fresh becomes true when the request is still valid against cache validators like ETag or Last-Modified.
4 people found this page helpful
