ellessuom
4/10/2019 - 3:30 PM

No cache headers on Nodejs

Set these headers on response:

'Cache-Control': 'private, no-cache, no-store, must-revalidate'
'Expires': '-1'
'Pragma': 'no-cache'

Using ExpressJS we can add this middleware to have no cache on all requests

// const app = express()
app.use((req, res, next) => {
    res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
    res.header('Expires', '-1');
    res.header('Pragma', 'no-cache');
    next()
});