Rule of optimization

As a qualified programmer, performance optimization is a required subject

Don’t Optimize too early: In typical Internet development patterns, rapid iteration and trial and error are pursued, and optimizing too early often becomes a waste of time

Do not over-optimize: At different stages of the project, the performance of the system will have different requirements. If it meets expectations, there is no need to spend time and effort optimizing

It’s about getting the right value for money: using the right solutions at different stages of the project to achieve the desired results

What happens from the time you enter the URL to the time the page loads?

  • The DNS

    The operating system checks whether the URL mapping exists in the local hosts file

    If there is no address mapping in the local hosts, the local DNS resolver cache is searched

    If the zone file and cache resolution of the local DNS server fail, the DNS server iterates query to resolve the problem

    Function: In distributed cluster mode, the DNS server translates host domain names into IP addresses

  • Establishing a TCP connection (three-way handshake)

The client and server exchange initial serial numbers of each other using SYN segments to maintain the same connection status. Chrome allows a maximum of six TCP connections to be established with a domain nameCopy the code
  • The client initiates an HTTP request

    The pipelining nature of the HTTP protocol allows a second request to be sent before the first reply is fully sent (multiple requests can be sent at once) to reduce communication latency

    However, when a response is received, it must be received in the order requested. If the previous request is blocked, the subsequent request still needs to wait for the blocking request to complete, even though it has been processed. This is also called queue head blocking

  • The server processes the request

    You can set different response headers to achieve different functions

  • The browser parses the rendered page

3. Combine THE DOM tree with the CSS rule tree. 4. Calculate DOM node information (node size, location) according to the rendering tree 5. Draw page according to the calculated information (CSS color, background, font, etc.)Copy the code
  • Close the TCP connection (four waves)

Ensure data integrity and close the connection after all data from the passive party has been transferred to the active partyCopy the code

conclusion

The so-called performance optimization is to ensure that the whole process from input URL to page loading is fast enough. Any problems in any link will affect the performance of the system