2

I have tried all the possibilities. Following are my response headers

HTTP/1.1 200 OK

Expires: Sun, 20 Dec 2015 03:53:42 GMT

Accept-Ranges: bytes

Cache-Control: public, max-age=604800

Last-Modified: Wed, 02 Dec 2015 15:49:21 GMT

Etag: W/"25571-15163623fb3"

Content-Type: image/png

Content-Length: 152945

Date: Sun, 13 Dec 2015 03:53:42 GMT

Connection: keep-alive

But still it's not returning 304 status. If I refresh command refresh in Firefox it's downloading that image again with 200 response code. I don't want that if user click command refresh it's should return 304 status. instead of downloading new file it should take it from browser cache.

Following is my nodejs code

var expireTime = 604800000;


app.all('/css*', function(req, res, next) {
  res.header('Expires', new Date(Date.now() + expireTime).toUTCString());
  next();
});   


app.use('/css',express.static(conf.nodePath + 'css',{ maxAge: expireTime}));

Can anyone guide me how to enable perfect cache. Thanks in advance..

lingeshram
  • 621
  • 9
  • 13
  • maybe try to use `.sendFile` in the route that you are setting the header and not calling `next()`. Maybe the other route overwrites the header when you pass the request to it. – Aᴍɪʀ Dec 13 '15 at 04:31
  • You don't need to set expire data manually , Just try "var oneHour = 3600000;app.use(express.static(path.join(__dirname, 'public'),{maxAge:oneHour}))'; When you finish code, try to delete all cache file from your browser, and test again – MikeZhang Dec 13 '15 at 07:32
  • 1
    Because static module based on server-static, you can get lots information from its docs https://github.com/expressjs/serve-static – MikeZhang Dec 13 '15 at 07:37

0 Answers0