5# Network Optimization.
#performancematters #fastweb #jvmtech #jvmperformanceseries

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

To view or add a comment, sign in

More articles by Thomas Feldhaus

  • The speed of use

    At the previous article "The perception of performance" we found out a lot about the human perception of time and speed…

    1 Comment
  • #19 The perception of performance

    Do milliseconds and kilobytes make the difference? In the previous articles on performance we have heard a lot about…

  • #18 Building a web performance culture.

    Web Performance is not a product feature that can be easily switched on and off, ideally the entire organization…

  • #17 AMP, Performance built-in.

    For 16 episodes we have now bombarded you with tips, tricks and ideas how you can improve the speed of your web app…

  • #16 Webassembly

    WebAssembly or short Wasm is a huge deal as it is enabling deployment of lower level language code on the web for…

  • #15 Image & Video Formats

    In the first years, the Web was a text-based wasteland with only a few image oases available solely through links. This…

    1 Comment
  • #14 PWA/Service Worker

    When thinking about performance, web technologies always had a reputation of being slow and sluggish, especially on…

  • #13 Web Performance Timing APIs

    If you are into web performance you surely stumbled upon very detailed numbers. No matter whether you measure…

  • 12 Javascript defer or async?

    When adding interactivity to our web pages we heavily rely on JavaScript. But adding JavaScript comes with a price.

  • #11 JavaScript Performance

    Nowadays, web applications are heavily interactive and make use of lots of JavaScript. May they be scripts we wrote for…

Others also viewed

Explore content categories