I wrote a simple Express node.js server to test out some HTTP caching stuff.
const express = require('express')
const serveStatic = require('serve-static')
const path = require('path')
const app = express()
app.use(serveStatic('build', {
extensions: ['html'],
setHeaders(res, path) {
res.setHeader('Cache-Control', `max-age=10`)
}
}))
app.get('*', function (request, response) {
response.sendFile(path.resolve(__dirname, 'build/200.html'))
});
const port = process.env.PORT || 3001
app.listen(port, () => console.log(`Listening on port ${port}`))
Interestingly without me explicitly adding ETAG with res.setHeader
, it seems like the response automatically comes with a weak ETAG something like ETag: W/"45b4e-181a6ae36a4"
. However, if I explicitly set the ETAG myself, e.g. res.setHeader('ETAG', md5(...))
then no weak ETAG occurs.
I wonder where weak-etag comes from and how that affects the cache invalidation. Would it behave the same as if I explicitly set the ETAG myself?
Here is a similar question on here but the answer there doesn't seem to apply to my case.