How to know when to send a 304 Not Modified response

前端 未结 5 1463
北荒
北荒 2020-12-30 07:35

I\'m writing a resource handling method where I control access to various files, and I\'d like to be able to make use of the browser\'s cache. My question is two-fold:

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 08:19

    You should send a 304 if the client has explicitly stated that it may already have the page in its cache. This is called a conditional GET, which should include the if-modified-since header in the request.

    Basically, this request header contains a date from which the client claims to have a cached copy. You should check if content has changed after this date and send a 304 if it hasn't.

    See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25 for the related section in the RFC.

提交回复
热议问题