How does “304 Not Modified” work exactly?

后端 未结 2 790
一个人的身影
一个人的身影 2020-11-28 02:40
  • How are \"304 Not Modified\" responses generated?

  • How does a browser determine whether the response to an HTTP request is 304?

  • Is it

相关标签:
2条回答
  • 2020-11-28 02:47

    When the browser puts something in its cache, it also stores the Last-Modified or ETag header from the server.

    The browser then sends a request with the If-Modified-Since or If-None-Match header, telling the server to send a 304 if the content still has that date or ETag.

    The server needs some way of calculating a date-modified or ETag for each version of each resource; this typically comes from the filesystem or a separate database column.

    0 讨论(0)
  • 2020-11-28 03:03

    Last-Modified : The last modified date for the requested object

    If-Modified-Since : Allows a 304 Not Modified to be returned if last modified date is unchanged.

    ETag : An ETag is an opaque identifier assigned by a web server to a specific version of a resource found at a URL. If the resource representation at that URL ever changes, a new and different ETag is assigned.

    If-None-Match : Allows a 304 Not Modified to be returned if ETag is unchanged.

    the browser store cache with a date(Last-Modified) or id(ETag), when you need to request the URL again, the browser send request message with the header:

    the server will return 304 when the if statement is False, and browser will use cache.

    0 讨论(0)
提交回复
热议问题