Should HTTP 304 Not Modified-responses contain cache-control headers?

前端 未结 3 1084
耶瑟儿~
耶瑟儿~ 2020-12-12 23:43

I\'ve tried to understand this, and searched SO for similar questions, but I still don\'t have a 100% understanding on how this is supposed to work.

I get this respo

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 00:24

    In theory you shouldn't have to send Cache-Control for a 304 -- the recipient should just continue to use the cache directives that it received from the original 200. However, as you've found, in practice if you don't keep sending Cache-Control, browsers will ignore the cache directives that you sent originally, and revert to their own default heuristics.

    So in practice, you should include the same Cache-Control with a 304 that you would with a 200. The spec only mandates that you send it for a 304 if it's different than what you sent previously (see 10.3.5 304 Not Modified) -- but it certainly doesn't forbid you from repeating it when it's the same.

    And to respond specifically to the wrong-headed points from the other answer (Structure's):

    1. You do want intermediary caches to cache the response (that is, update their cache entry for the resource). They will respond appropriately to requests from clients with a 200 or a 304, depending on whether the client included a conditional header like If-Modified-Since.

    2. The 120-second ttl will be refreshed by the 304 (so the same client shouldn't make another request for the same resource for at least another 120 seconds). And clients, as long as they've still got the content cached, will continue to make conditional requests for the resource, which you can continue to respond to with a 304.

提交回复
热议问题