Sobes.tech
Middle

What are the advantages of loading external resources from multiple domains?

sobes.tech AI

Answer from AI

Loading external resources from multiple domains (domain sharding) allows bypassing the browser's limit on the maximum number of simultaneous connections to a single domain. Usually, this limit is 6-8 connections.

Advantages:

  • Increased loading speed: The browser can load more resources in parallel, reducing the overall page load time.
  • Bypassing browser restrictions: Overcomes the limit on the number of parallel HTTP requests to the same host.
  • Load distribution: The load from one main web server is redistributed across several.
  • Use of CDN: Enables efficient use of resources located on Content Delivery Networks (CDNs), which often serve content from different domains.

Example pseudocode demonstrating parallel script loading from different domains:

<!-- index.html -->
<script src="https://domain1.com/script1.js"></script>
<script src="https://domain2.com/script2.js"></script>
<script src="https://domain3.com/script3.js"></script>
<script src="https://domain4.com/script4.js"></script>

Despite the advantages, there are potential drawbacks:

  • Additional DNS lookup: Each new domain requires a separate DNS request, which can add a slight delay.
  • HTTP header size: Standard HTTP headers (e.g., cookies) are sent for each resource, which can increase total traffic volume.

Overall, domain sharding is an effective technique for improving web page load performance when the number of external resources is large. However, it is important to strike a balance and not create an excessive number of subdomains to minimize DNS request and header overhead.