HTTP: protocol that allows browsers to retrieve resources from the server
The browser initiates the HTTP request process
1. Build the request
Build the request line information GET /index.html HTTP1.1 and then prepare to initiate the request
2. Find the cache (before the actual request is made)
Browser cache: saves a copy of the resource locally for direct use by the next request. If there is a copy -> intercept request -> Return copy -> end the request
- Reduce server pressure and improve performance
- For web sites, caching enables fast loading of resources
**3.** Prepare IP addresses and ports
Domain Name System (DNS) : mapping IP addresses and Domain names
- The browser requests DNS to return the corresponding IP address (DNS data caching can reduce a network request)
- Port number: URL not specified, default port 80
4. Wait **** to wait for the TCP queue
- Http1.1 A maximum of six TCP connections can be established in the same domain name. A TCP connection can process only one request at a time
- Http2 can request resources in parallel, maintaining one TCP connection per domain name
5. Establish the ****TCP connection
6. Send ****HTTP request: Sends a request line to the server
The server side handles the HTTP request flow
1. Return the request
2. Disconnect the device
Connection: keep-alive Enables the browser to continue sending TCP requests through the same TCP Connection. This saves the time for establishing a Connection for the next request and speeds up resource loading
3. The redirection
conclusion
-
Why do some sites open faster the second time
-
DNS cache
-
Page resource cache
-
The server returns an HTTP response header. The browser sets whether to Cache the resource and the Cache expiration time by cache-control: max-age =2000
-
If the cache expires, the browser continues to make requests and puts if-none-match in the HTTP request header :” 4f80F – 13C-3a1XB12a “The server uses if-none-match to judge whether the requested resources have been updated
-
Priority: Cache-Control > Expires Etag > last-Modified
-
Cache-control: max-age: Cache duration (s) S-maxAge: Cache duration for the proxy server Public: can be cached by any Cache private: can only be cached by an individual user, but cannot be cached by the proxy server no-cache: Will be cached, but each time a request is made, the cache evaluates the validity of the cache response to the serverCopy the code
-
How is the login status maintained