What are the required http headers to tell the browser to cache an image forever, when sending it via Node.js?
Asked
Active
Viewed 1,711 times
0
-
Look [here](http://stackoverflow.com/questions/7790825/nodejs-express-framework-caching). – robertklep May 25 '13 at 13:50
1 Answers
1
Here we go:
if (!res.getHeader('Cache-Control') || !res.getHeader('Expires')) {
res.setHeader("Cache-Control", "public, max-age=345600"); // ex. 4 days in seconds.
res.setHeader("Expires", new Date(Date.now() + 345600000).toUTCString()); // in ms.
}

jmingov
- 13,553
- 2
- 34
- 37
-
1Just to clarify, this only caches for 4 days, right? That doesn't seem all that permanent to me. – D.Tate Mar 23 '16 at 01:05