5# Network Optimization.
Since the earliest days of the Internet, they are the backbone of every page view: Hypertext Transfer Protocol, or HTTP, and DNS, the Domain Name System.
It’s a two-step procedure. First, the browser takes the hostname from any given URL and feeds it into DNS to lookup the IP address of the remote server. Then, after connecting the server, HTTP is executed to load the desired data. It’s a stateless, repeated procedure, done for every asset needed. So it takes time. Time which can be reduced by suitable measures.
Evolution of HTTP
It took eight years from the invention of HTTP by Tim Berners-Lee in 1989 to HTTP/1.1, the proper standardization in 1997. For more than two decades HTTP/1.1 has been used to deliver the World Wide Web.
HTTP/1.1 introduced many performance friendly features like connection reuse, chunks, and cache control. But it’s still a single-document-protocol and content heavy sites have to use sprites and domain sharding to achieve a neat performance.
Then, in 2015, HTTP/2 evolved for greater performance. The protocol is binary, multiplexed over one connection, and uses compressed headers. Server push allows adding data to the client cache, in advance of it being required. Today, HTTP/2 is used by 44% of all websites.
The next level, HTTP/3, is due for publication shortly. With the move from TCP to UDP communication setup is faster and content transfer more stable. The proposed successor to HTTP/2 is already available in Chrome, Firefox, and Safari.
Reduce your DNS footprint
On average, a single DNS lookup requires between 20-200 milliseconds to complete, depending on network speed, DNS provider, and location. Valuable time, which can sum up to several seconds for a website with a good deal of content suppliers and marketing tools.
DNS speed of jvm.com, source: https://www.dnsperf.com/dns-speed-benchmark
To reduce your DNS footprint you should do less DNS lookups, without unnecessary repetition, prioritized, and preferably fast.
The first and most promising optimization is to reduce DNS lookups and deliver as much as possible over a single domain. For example, do not use subdomains for assets like https://images.example.com/. It’s faster to use folders to structure your data, e.g. https://example.com/images. The same applies to 3rd party content like Google Fonts or JavaScript libraries. Use your own server or CDN and get rid of DNS lookups for 3rd parties.
DNS lookups are cached in browser and (intermediate) name server. As long as the cache is not expired subsequent lookups can be provided without connecting another server. As a guide a timeout of 24 hours (86.400 seconds) is recommended.
To prioritize DNS handling for resources needed above-the-fold instruct your browser with hints in HTML header (<link rel="dns-prefetch" href="https://subdomain.example.com/" >) or HTTP response (Link: <https://subdomain.example.com/>; rel=dns-prefetch). Other resources like JavaScript for analytics or re-targeting are not needed immediately on load. If they are loaded asynchronously, their DNS footprint is deferred, too.
DNS lookups are slow if you use CNAME since the name server has to resolve a second domain. You might need CNAMES for infrastructure like CDN. But if not, prefer using A and AAAA records.
Finally, a fast DNS provider helps to speed up the remaining DNS lookups.
Average speed of authoritative DNS providers, source: https://www.dnsperf.com/
- https://developer.mozilla.org/en-US/docs/Web/Performance/dns-prefetch
- https://www.dnsperf.com/
Tomorrow follows: #6 Caching, Local Storage, CDN & Infrastructure.