"turn" [translate] Understand http/304 response

Source: Internet
Author: User

"turn" [translate] Understand http/304 response

Original: http://www.telerik.com/automated-testing-tools/blog/eric-lawrence/12-11-06/understanding-http-304-responses.aspx

Users who are just beginning to use fiddler are often puzzled by the http/304 response in the Fiddler network session (web SESSIONS) list :

If the client sends a conditional validation (Conditional Validation) request , the Web server may return a http/304 response, which indicates that the cache of the requested resource in the client is still VALID. This means that the resource has not been modified since it was last cached. conditional requests can be used to ensure that the Client's resources are up-to-date while avoiding the performance issues associated with requesting full resources each Time.

Identify a condition request

A conditional request is sent when the client caches the target resource but is not sure whether the cache resource is the latest version. in fiddler, you can find the relevant request header in the Headers Inspector , so that you can tell if a request is a conditional request.

When a conditional request is made, the client provides a if-modified-since request header to the server with a value of the date value in the last-modified response header that was last returned by the server, and a The If-none-match request Header value is the value of the ETag response header that the server last Returned:

The server reads the values in both request headers to determine if the client caches the resources are up-to-date, and if so, the server returns a http/304 not Modified response, but no response body. after the client receives a 304 response, The corresponding resource is read from the Cache.

alternatively, if the server considers that the client cache resource has expired, the server returns the http/200 OK response, which is the most current content of the RESOURCE. after the client receives a 200 response, it overwrites the old cache resource with the new response Body.

A conditional request can be sent only if the client has cached the corresponding resource and the Resource's response header contains a last-modified or ETag . If none of the two headers exist, you must unconditionally ( Unconditionally) requests the resource, the server must also return the full resource Data.

Why use conditional requests

When a user accesses a web page, the conditional request accelerates the Page's opening time (because it saves time to transmit the entire response body), but there is still network latency because the browser has to generate a conditional request for each resource and wait until the server returns a http/304 response. To read the cache to display the Web Page. ideally, the server specifies the Cache-control or expires directive on the response so that the client can know how long the resource is available, and can skip the conditional request step and directly use the resources in the Cache. but, Even if the server provides this information, you still need to use conditional requests in the following situations:

    • After the expiration time specified by the server is exceeded
    • If the user performs a refresh operation

In the picture given in the previous section, a Pragma:no-cacheis included in the request Header. this is because the user has refreshed the Web page with F5 . If the user presses the ctrl-f5 (sometimes called a "strong brush-hard Refresh "), you will find that the browser omits the if-modified-since and If-none-match request headers, which is the unconditional request for each resource in the Page.

Avoid conditional requests

In general, caching is a good thing. if you want to improve your Site's access speed, caching must be Considered. however, when debugging, it is sometimes necessary to block the cache to ensure that the resources you access are Up-to-date.

You may have a question: "how can I let fiddler not return 304 and return a http/200 response with a response body without changing the content of the site?"

You can select a session in the network session (web SESSIONS) list in Fiddler that responds to http/304, and then press the U key. fiddler will be Re-Sent unconditionally ( Unconditionally Reissue) This request. then use the compare command to compare the difference between the two requests, the comparison results are as follows, it can be learned that the Fiddler is to omit the conditional request header to implement a Cache-free request :

If you want to block the http/304 response globally, you can do this by first clearing the Browser's cache, using the Clear Cache button on the Fiddler toolbar (only the Internet Explorer cache can be cleared), or by pressing CTRL on the browser +shift+delete (supported by all browsers). after clearing the Browser's cache, go back to fiddler and select the Rules > Performance > Disable Caching option in the MENU. Then Fiddler: deletes all requests in the condition request with the same request header and all responses in response to the cache time-related response header. in addition, the pragma:no-cache request header is added to each request, and each response is added Cache-control:no-cache The response header to prevent the browser from caching these Resources.

"turn" [translate] Understand http/304 response

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.