My website domain name is www.yining.org. There is a page (for example, this blog entry) with an image. Its SRC is/img/camel.gif, and its URL is: "http://www.yining.org/img/camel.gif.pdf ". If a cookie is set on this page (for example, to record the message holder's ID and website address), the cookie domain name is automatically www.yining.org. Every time you access this page, because the Domain Name of the URL is www.yining.org, the browser will send a request to the image with a cookie. Even if the Web cache along the way has a record of www.yining.org/img/camel.gif, it will still be sent to the origin server ), instead of returning from the intermediate Web Cache-because requests with cookies may return different response values based on different cookie values.
However, this is not ideal for many static resources (images, CSS, and JavaScript), because no matter what the cookie is, their response contains the same content, there is no need to return to origin server every time for requests. Second, because different Web Cache supports different requests with cookies, even if some cache can cache response with cookies, but 1) not most of the cache can do this, 2) most of the caches default cache response without cookies. Therefore, the best way is to use different domain names to isolate static resources. Although the path attribute of the cookie can also achieve this, there are too many restrictions, so it is better to use specialized domain names flexibly.
therefore, we should try to separate all static objects from dynamic page domain names. More strictly speaking, is to separate the server resources that do not need to read and write client cookies from the Program that needs to read and write cookies to different domain names. For example, I can set another domain name static.yining.org and change the src attribute in the referenced in the image to "alias (because the domain name is different now ), in this way, the Web cache and server performance can be better utilized. I have consulted a person who once worked in netappliance (the largest Web Cache vendor). According to his experience, the difference between with and without cookies may be 20% or even greater.