I want to disable Etag and Last-Modified headers for index.html files served by express.static, how can I accomplish this?
I tried:
app.use(express.static('public', {
setHeaders: function(res, path){
if (path.match(/index\.html$/)){
res.removeHeader('Etag')
res.removeHeader('Last-Modified')
}
}
}));
But it doesn’t work, Etag and Last-Modified still in response’s headers.
For ETag, just set
etag: false
in the options:The
send
module (which is used behind the scenes) does not provide an option to not set theLast-Modified
header (I can make it do that in time). You would have to useon-headers
to unsetLast-Modified
OR if you only want to not send these headers for a certain path: