Why not use domain names to communicate directly

The LENGTH of an IP address is fixed: 32-bit for IPV4 and 128-bit for IPV6. The domain name is relatively long, which is not conducive to computer processing

IP addresses are difficult for users to remember and not semantic enough. Domain names are easier for users to remember

To sum up: IP addresses are host-oriented, whereas domain names are user-oriented

Getting to know hosts files

  • What is the hosts file

    A system file without an extension that can be used to store the mapping between domain names and IP addresses

    When a user accesses a page, the system automatically searches for the IP address in the hosts file and establishes a TCP connection immediately. If the IP address cannot be found, the system submits it to the DNS server for IP address resolution

  • Modifying the hosts file

    Edit the hosts file in the Mac system

    In Windows, edit the hosts file

    Note: all comments starting with # are not valid

DNS Domain name resolution process

DNS optimization

  • Automatic parsing

    During page loading, the browser automatically resolves the domain name in the href attribute of the hyperlink to an IP address

    Automatic resolution is not allowed on HTTPS pages. You can manually set resolution

  • Manual parsing

    Enable the pre-resolution function for a specified domain name to optimize CDN resources

    <link rel="dns-prefetch" href="//file.cdn.com">
    Copy the code

    Enable automatic HTTPS page resolution

    <meta http-equiv="x-dns-prefetch-control" content="on">
    Copy the code
  • Enable automatic HTTPS page parsing through the server response header

    X-DNS-Prefetch-Control: on
    Copy the code

    On: enabled; OFF: disabled

conclusion

DNS requests consume very little bandwidth, but the latency is high, especially on mobile networks. DNS pre-resolution can significantly reduce some latency

For example, it can reduce the wait time for users to click a link

Review past

Performance Optimization Issue 01 – Building a performance knowledge body