Express req.stale Property
What you’ll learn
- What
req.stalemeans in cache revalidation. - How to pair
req.stalewith ETag/Last-Modified headers. - How to send full content only when cache is stale.
- How
req.stalediffers fromreq.fresh.
Usage syntax
javascript
req.stale
req.fresh1
Send content when cache is stale
javascript
app.get('/feed', function (req, res) {
res.set('ETag', '"feed-v3"');
if (!req.stale) return res.status(304).end();
res.json({ updated: true, items: [] });
});2
Use stale check with Last-Modified
javascript
app.get('/news', function (req, res) {
res.set('Last-Modified', new Date('2026-05-02').toUTCString());
if (!req.stale) return res.status(304).end();
res.send('Fresh news payload');
});❓ FAQ
It indicates that the cached representation is stale and content should be re-sent.
req.stale is effectively the inverse of req.fresh in conditional request handling.
When validators like ETag or Last-Modified do not satisfy the client's conditional headers.
Yes, especially for GET endpoints that support conditional caching behavior.
Yes. Set ETag/Last-Modified and related headers correctly for predictable results.
Did you know?
req.stale is the opposite of req.fresh; when true, the client cache is not valid and content should be sent.
4 people found this page helpful
