Browser HTTP cache mechanism and cache rule parsing, cache mechanism rule Parsing

Source: Internet
Author: User

Browser HTTP cache mechanism and cache rule parsing, cache mechanism rule Parsing

When a static file (image, css, js) is requested, these files are stored as files that do not change frequently, the client is a method to optimize user browsing experience. So this is the significance of the client cache.

The Http cache mechanism is an important means to optimize web performance. Many users only know why the browser caches the requested static files, and how the cache takes effect, but it is not very clear.

1. cache-related header fields in the http message

Let's take a look at the cache-related fields in the 47 types of http packet header fields specified by RFC2616, so that we can have a bottom point in our hearts:

Common header field (that is, fields that can be used in both request messages and response messages)

Request Header field

Response Header field

Object header field

There are several methods to set browser cache:

Expires: The file expiration time in the local cache directory (specified by the server)

Cache-control: the file expiration time in the local Cache directory (the expiration interval specified by the server, because the browser generates the specific time according to the interval)

Last-Modified: Last modification time of the file on the server

Etag: File ID

2. cache rule Parsing

There are multiple HTTP cache rules, which are categorized based on whether or not requests need to be initiated to the server. I divide them into two categories (mandatory cache, comparison cache)

Before introducing these two rules in detail, we will first use the time sequence diagram to give you a simple understanding of these two rules.

When cached data already exists, it is only based on forced caching. The request data process is as follows:

When cache data already exists, it is only based on comparison cache. The request data process is as follows:

We can see that the two types of cache rules are different. If the forced cache takes effect, you do not need to interact with the server. However, whether the cache is effective or not, you need to interact with the server.

The two types of cache rules can exist at the same time. The priority of the mandatory cache is higher than that of the comparative cache. That is to say, when the mandatory cache rule is executed, if the cache takes effect, the cache is used directly and the comparison cache rule is no longer executed.

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.