Why do big web sites put their CDNs under different domain names?
March 23, 2018 8:31 AM   Subscribe

This is purely idle curiosity, but I've been wondering why Twitter-hosted images are served from twimg.com, and Facebook media from fbcdn.com, rather than something like img.twitter.com or cdn.facebook.com. What's the point of using a whole new domain name instead of a subdomain?
posted by moonmilk to Computers & Internet (5 answers total) 9 users marked this as a favorite
 
Best answer: If I have cookies set for facebook.com, all requests to cdn.facebook.com will include those cookies, which increases the number of packets needed to make the request. So you use a different domain, and there's no overhead because of cookies.
posted by Jairus at 8:40 AM on March 23, 2018 [3 favorites]


Best answer: What Jairus said, except it's also (mainly?) a security consideration. If the domains are the same, and a malicious script or page managed to run off the CDN (plausible since these are often user-submitted content), that script would get access to all the main site's cookies and would have a good foothold toward launching a cross-site scripting attack or similar. An attacker would also be able to bypass the same-origin policy.
posted by neckro23 at 9:20 AM on March 23, 2018 [4 favorites]


Best answer: The historical reason — which still applies with non-HTTP2 requests — is that browsers will limit in-flight connections made per-domain. Each image, script, etc., under HTTP, requires a separate request, and a separate connection. The number varies, I remember 4 at-a-time with Mozilla back in the day. So if you have a site that is loading up 100 different assets, if you can split those assets over multiple domains, you can reduce the latency of the page loading by having more things downloading at once.
posted by jraenar at 9:23 AM on March 23, 2018 [4 favorites]


Response by poster: Thanks - it all makes sense now!
posted by moonmilk at 9:48 AM on March 23, 2018


A couple answers mentioned Content Distribution Networks without going into detail there, but in general it's much easier to set up a CDN to serve static content from a different domain than your dynamic site, given that they'll usually live on entirely different servers to begin with. (In addition to all the reasons given above.)
posted by Aleyn at 1:52 AM on March 24, 2018


« Older Scheduling Volunteers for a non-profit   |   Find My Friend's Mom on an Episode of Sally Jessy... Newer »
This thread is closed to new comments.