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

Example Analysis of http Cache in web

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you the "sample analysis of http cache in web", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn the article "sample analysis of http cache in web".

Why is there a http cache?

1. When you enter the URL to load the page, the computer will go through a series of steps such as "CPU calculation, network request, page rendering" and so on.

2. "Network request" is one of the most uncertain and time-consuming links. For this link, we can load the page faster by "reducing the size and number of network requests", which is the reason for the existence of "cache".

3. Through "caching", you can "reduce the size and number of network requests"

Mandatory caching of http caching

1. When visiting a website for the first time, the back end of the website thinks that the requested resources (css, js, pictures, etc.) should be cached by the browser.

two。 The backend adds a configuration to the response header:

Cache-Control: max-age=12146545 (in seconds)

3. When we request the site again, we will read the resources directly from the local cache and will not request the cached resources from the server.

4. If the cache resource expires, all resources are requested from the server, and the resources with configuration items are cached again

The setting of 5.Cache-Control, which is determined by the backend developer, does not involve the front end. Of course, it can also be set to no cache: Cache-Control: no-cache

Negotiation cache for http cache (comparison cache)

1. Negotiation cache is a caching strategy on the server side.

two。 When you visit a website for the first time and send a request, the server returns the resource and resource ID. The browser will cache both the resource and the resource identity

3. When the request is sent again, the resource ID will be taken. The server will compare the resource ID in the request with the latest resource ID in the server:

If consistent: the server only returns 304, the browser will get the resource directly in the cache (reduce the volume of the requested data)

If inconsistent: the server will return 200 and the requested resource and the latest resource ID (it will be relatively larger)

Negotiate resource identification in the cache

There are two types of resource identifiers. When a request is sent, it is placed in the request header:

Last-Modified: when the resource was last modified

If-Modified-Since: xxxxx (key name is not the same as Last-Modified)

ETag: the unique string of the resource object

If-None-Match: xxxx (key name is not the same as Last-Modified)

The question of priority

Generally speaking, ETag is preferred because the value of Last-Modified is only accurate to seconds.

If the file is generated repeatedly at regular intervals, but the content is the same.

Last-Modified returns the resource file every time, even if the content is the same.

But Etag can tell that the contents of the file are the same, and it will return 3040.Use the cache.

The above is all the content of the article "sample Analysis of http caching in web". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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