express returns 304 for IE repeative requests

前端 未结 3 493
暖寄归人
暖寄归人 2021-02-08 05:35

I\'m experiencing some strange behavior of ExpressJS. On second request to my node.js/express based API URL it always returns 304 Not Modified response code to IE. Other browser

3条回答
  •  既然无缘
    2021-02-08 05:45

    The Cache-Control header is a workaround. The bug is in internet explorer's interpretation of the HTTP 1.1 spec for the header.

    I added this to my route handler, which solved the problem. You also need a Last-Modified or ETag header, but express was already sending that for me.

    res.setHeader("Expires", "-1");
    res.setHeader("Cache-Control", "must-revalidate, private");
    

    See: Make IE to cache resources but always revalidate

提交回复
热议问题