Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the origin of HTTP 200OK and HTTP 304Not modified

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to analyze the origin of HTTP 200OK and HTTP 304Not modified. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Both of these fields are related to the cache control of the HTTP protocol.

The browser caching mechanism is implemented through fields such as Cache-Control (or Expires) and Last-Modified (or Etag) in the HTTP protocol Header.

The purpose of these two fields:

1. When receiving the response, the browser decides whether the file needs to be cached

two。 When the file needs to be loaded, the browser decides whether the requested field is required.

Look at some examples:

Cache-Control:max-age=115360000, indicating that the cache is valid for 115360000 seconds. If the file needs to be requested again within 115360000 seconds, the browser will not issue a request to the server, but will directly use the locally cached file. This is a field in the HTTP/1.1 standard.

In general, you can see the from disk cache prompt in the Network tab of the Chrome developer tool:

Reading files from the local cache is very fast, and the above example took only 6 milliseconds:

Expires: Thu, 31 Dec 2018 23:55:55 GMT, indicates that the file expires at 23:55:55 on December 31, 2018, before which the browser will not make another request to get the file. This is the field in HTTP/1.0.

You can see this in the network tab of the Chrome developer tool:

The following two fields are the fields that the server decides whether the file needs to be updated when the request is initiated.

Last-Modified: Thu, 26 Jul 2018 05:41:21 GMT, which means that this file was last modified at 05:41:21 on July 26th, 2018.

The browser will bring the value of Last-Modified as the If-Modified-Since field of Request Header the next time it requests it. If the file cached by the browser has exceeded the Cache-Control (or Expires), a request will be issued when the file needs to be loaded. The requested Header has a field of If-Modified-Since, as shown in the following figure:

After receiving the request, the server will compare the Last-Modified time of the file with this time. If the time does not change, the browser will return 304 Not Modified to the browser:

If the time changes, the server will return 200 OK and return the corresponding content to the browser.

The get_header_field method in line 9 below is that the server extracts the value of the header field If-Modified-Since from the HTTP request sent by the browser.

The set_header_field method in line 16 below is for the server to set the value of the Last-Modified header field.

The following figure shows where the server sets the 304 Not Modified response:

This is the origin of how to analyze HTTP 200OK and HTTP 304Not modified that the editor shared for you. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report