Graphical browser cache

1、Last-Modified

In the browser first request a particular URL, the server returns the status is 200, the content is the resource you request, but there is a Last-Modified attribute tag (HttpReponse Header) This file is in the service of the end of the last modified time, format like this:

Last-Modified:Tue, 24 Feb 2009 08:01:04 GMT

When the client makes a second request this URL, in accordance with the provisions of the HTTP protocol, the browser sends If-Modified-Since header (HttpRequest Header) to the server asked whether after the time of the file has been modified:

If-Modified-Since:Tue, 24 Feb 2009 08:01:04 GMT

If there is no change in the resource server, automatically returns HTTP304 (NotChanged.) Status code, the content is empty, thus saving the amount of data transferred. When the server-side code changes or reboot the server, reissue the resource, and the like returns the first request. Thus ensuring the client not to issue duplicate resources, but also to ensure that when the server changes, the client can get the latest resources.

Note: If the If-Modified-Since time later than the current server time (the current request time request_time), the request will be considered illegal

2, Etag works

ETag HTTP protocol specification is defined as "the requested entity tag variable" (see 14.19). I.e., a simple point to the URL request server response marker, in the head and transmits it to the client in response to HTTP, the server returns a similar format:

Etag:“5d8c72a5edda8d6a:3239″

The client update query format is as follows:

If-None-Match:“5d8c72a5edda8d6a:3239″

If the ETag not change, then the state 304 return.

That is: After the client request, HttpReponse Header contains Etag: "5d8c72a5edda8d6a: 3239"

Logo, tells the Client side, you get this resource indicating ID: 5d8c72a5edda8d6a: 3239. When the next time you need to ask the same hair Request URI when the browser also issued a Etag If-None-Match header (Http RequestHeader) At this header contains information obtained last visit: "5d8c72a5edda8d6a: 3239" logo.

If-None-Match:“5d8c72a5edda8d6a:3239“

So, Client-side Cache equal to the two, the server will etag than 2 persons. If the If-None-Match is False, does not return 200, returns 304 (Not Modified) Response.

3、Expires

After the date / time of analysis, the response is considered obsolete. Such as Expires: Thu, 02 Apr 2009 05:14:08 GMT

And the need to use binding Last-Modified. Effective time to control the requested file, when a client requests data browser to request data from the cache rather than over the life of the server. When the cache data invalid or expired before deciding to update data from the server.

4、Last-Modified和Expires

Last-Modified identification bit save bandwidth, but still can not escape out send an HTTP request, and to be used together and Expires. And Expires identity is making a browser altogether with HTTP requests are not made, such as when the user F5 or click the Refresh button even when there Expires for URI, and the same will send a HTTP request to go out, so, Last-Modified or want to use , but also to use and Expires together.

5、Etag和Expires

If the server at the same time and provided the Expires Etag, Etag same principle, i.e. the Last-Modified / Etag corresponding HttpRequestHeader: If-Modified-Since and If-None-Match. We can see the Last-Modified value both Header and WebServer issued, Etag exactly the same value; after exact match If-Modified-Since and If-None-Match that is modified and checked the Etag, the server can return 304 .

6、Last-Modified和Etag

Distributed systems across multiple machines last-modified document must be consistent, so as not to load balance to a different machine than the cause of the failure

Distributed systems try to close off Etag (each machine-generated etag will be different)

Last-Modified be used with the http header ETags request, the server first generate Last-Modified / Etag mark, the server can use it later to determine whether the page has been modified, to decide whether to continue the cache file

Process is as follows:

  • The client requests a page (A).
  • Server returns a page A, and adding a Last-Modified / ETag to A.
  • Client to show the page, and the page along with the Last-Modified / ETag cache together.
  • Customer requests the page again A, passed to the server with the time and the last request server returns Last-Modified / ETag.
  • The server checks the ETag or Last-Modified, and determines that the page has not been modified since the last client request 304 and returns a response directly to an empty response body.

Note:

  • HttpReponse Header Last-Modified header and Etag are issued by the WebServer, WebServer should support both heads.
  • After transmission WebServer Last-Modified / Etag header to the client, the client caches the head;
  • When the client sends a request the same page again, are transmitted to the Last-Modified / Etag corresponding HttpRequestHeader: If-Modified-Since and If-None-Match. We can see the Last-Modified value both Header and WebServer issued, Etag exactly the same value;
  • To the server to check the above value, determines whether to continue the cache file;
7, Cache-Control on: max-age = seconds and Expires
Expires = time, HTTP 1.0 version, the cache set only time, not allowing the client to check (Request) before this time
max-age = seconds, HTTP 1.1 version, how many seconds the resources cached locally.
If the max-age and Expires exist, max-age were covering the Cache-Control.
Expires One drawback is that the expiration time to return a server-side time, so there is a problem, if the client and server time to time vary widely, so it is a great error, so the beginning of the HTTP 1.1 version, use the Cache-Control : max-age = seconds instead.
Expires = max-age + "current time of each download request."

So once again after the download page, expires recalculated once, but last-modified will not change

Reproduced in: https: //www.cnblogs.com/JoannaQ/p/4417126.html

Guess you like

Origin blog.csdn.net/weixin_34109408/article/details/93057581