Not able to set cache-control header for my static resources Express
Your code looks right, the only thing is you are setting the option maxage
instead of maxAge
. This works as expected:
app.use(express.static(path.join(__dirname, "..", "client/build/static"), { maxAge: 31536000}))
You can see the list of options for static files here: https://expressjs.com/en/api.html
You can specify in this other way the cache control header and it will cache accordingly. The idea would be to add a call to res.set() prior to any output.
res.set('Cache-Control', 'client/build/static, max-age=31557600');