0

I'm using Express and Node to build a web, where the client uses RESTful API to get Json response to show a list of objects.

After creating a new object, the app should request a new json response of the updated object list. Chrome works fine - new json response returned with status code 200 OK. However, things are not good in IE and Edge - it seems the browser just fetch the json response from cache (with status code 304), instead of making a new request. If I manually clear the browser cache data things will be fine.

I tried this solution: using a middleware to set max-age of cache-control res.header to be 0

function headerSet(req, res, next) {
  res.header('Cache-Control', 'public, max-age=0');
  return next();
}

And in the response header I can see accordant settings taking effect, however, IE and Edge still refuse to make a new request - I'm still getting the unupdated json response with 304.

What possibly have I done wrong?

Community
  • 1
  • 1
Stanley Luo
  • 3,689
  • 5
  • 34
  • 64
  • A [304](https://httpstatuses.com/304) means that it's your _server_ that's telling the browser that the data didn't change. So there's something at fault in your server logic. Are you using any particular Express middleware that may be causing the problem? You could also try changing Express's [`etag`](http://expressjs.com/en/4x/api.html#etag.options.table) setting (try changing it to `strong`). – robertklep Oct 27 '16 at 07:54

1 Answers1

3

Instead of setting max age try with the following.

res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
XCEPTION
  • 1,671
  • 1
  • 18
  • 38