There are two things to consider when dealing with cache in Express.js – ETag
and Cache-Control
headers.
ETag (MDN reference)
If you have dynamic content which does not benefit from ETags, it’s best to disable it because it incurs small overhead with each request.
app.set('etag', false)
Cache-Control (MDN reference)
To completely disable cache, use the following header:
app.use((req, res, next) => {
res.set('Cache-Control', 'no-store')
next()
})
This header does not affect express.static()
middleware. It handles cache in its own way.