How it is possible to setup a cach-controll policy in express.js on json response? My json response does't change at all, so I want to cache it aggressively. I found how to do caching on static files but can't find how to make it on dynamic data.
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Axios OPTIONS instead of POST Request. Express Res
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- Is there a google API to read cached content? [clo
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
res.set('Cache-Control', 'public, max-age=31557600, s-maxage=31557600'); // 1 year
The inelegant way is to simply add a call to
res.set()
prior to any JSON output. There, you can specify to set the cache control header and it will cache accordingly.Another approach is to simply set a
res
property to your JSON response in a route then use fallback middleware (prior to the error handling) to render and send the JSON.Edit: Changed from
res.setHeader
tores.set
for Express v4