Why do sites like Facebook, Twitter, and Google host their images and css on external domains such as:
- Is is performance? or Security?
migrated from webapps.stackexchange.com Mar 3 '12 at 23:43
This question came from our site for power users of web applications.
@toomanyairmiles is partially correct - the purpose of this technique is to allow parallel connections from the web-browser to the server. Web browsers should allow a minimum of two simultaneous connections to a single host, but many new browsers can manage up to 60. Regardless, concurrent simultaneous connections between browser and web-server(s) is a major speed bottleneck.
From Google's resource:
So the way to get around this is to "shard' the requests to either different domains, or hosts:
Again, from the same Google resource:
Many companies also use a CDN, a tool which ensures the end user gets their data from a server that is geographically close to them, which also increases site performance by reducing the roundtrip time for resource requests.
Large sites move their static content (images, JS & CSS files) to a Content Delivery Network or CDN as deploying your content across multiple, geographically dispersed servers will make your pages load faster from the user's perspective.
As the CDN has a different domain name, it also provides domain sharding benefits.
The 2-item restriction is not an issue any more. While it's a recommendation of the HTTP spec, all modern browsers allow at least 6 concurrent connections.