A picture
https://codeshelper.com/img/.
is attached.
strong cache directly uses the local cache (judged by Expires or Cache-Control) and returns directly from the local after a hit. If you fail, with Last-Modified or Etag and server confirmation, you may pass through the CDN server during the confirmed network transmission. If the CDN server has a local cache, it can return 304 (valid resources) or 200 (invalid client resources, return local resources to the CDN server) according to the resource situation, which is consistent with the logic of the terminal server.
there are two properties in Cache-Control related to the CDN server,
- public, can be cached by all terminals, including CDN servers
- private, can only be cached by terminal browsers, but not by relay servers such as CDN servers.
these three concepts do not conflict. Strong caching is a local cache, which is directly used within the validity period. After expiration, you need to go to the server to verify (that is, the negotiation cache). During the negotiation process, you may go through the CDN server, and the CDN cache will come out. So whether you turn on CDN caching or not, it does not affect the logic of strong caching and negotiation caching
this question, let me say a little bit of my understanding, may not be very accurate, but I hope it will be helpful to you.
In a nut
shell, this CDN cache is two different things
from strong caching and negotiation caching itself. Strong caching and negotiation caching refer to the type of policy in which the browser dec
ides whether the cache is hit when loading a static resource. The general process is as follows:
- first of all, determine whether the resource hits the strong cache according to its http header. If so, the request will not be sent to the server. You can use the local cache directly
.
- if the strong cache fails, a request will be sent to the server for confirmation. Here is the negotiation cache. The negotiation process will determine whether the negotiation cache is hit according to the configuration of the server, the http header sent by the request and other information. If it is hit, the browser will still directly use the local cache
.
the principle of CDN cache acceleration is that it caches resources on the node, so that when accessing a resource, you can directly access the CDN node instead of the origin server. Whether you are referring to skipping strong caching and negotiation caching in your question depends on the configuration. In general, if you configure CDN, there must be a console that asks you to enter some parameters, such as content, expiration time, weight, and so on. The significance of these parameters is that when the browser interacts with the CDN node, it will decide whether to return the cache resource directly or forward the request to the origin server based on these parameters and the configuration of your origin server (the specific rules are very complicated. You can find articles online for more information). It is up to the origin server to decide what kind of resources to return, and the process also includes the parsing process of strong caching and negotiation caching described in the above paragraph.
above, personal humble opinion, big god light spray.