tags:

views:

54

answers:

3
+2  Q: 

CDNs and domains

Hi all!

A lot of big websites (facebook etc) are settings up CDN's for their content. Now I notice, that these CDN's are not always on the original domain.

Example: Facebook pictures are on "photos-a.ak.fbcdn.net"

Why is that? Is there a performance-gain in not having lots of subdomains on the "primary" domain (facebook.com)

+1  A: 

There is quite a large performance gain for the user because with a different domain, the browser won't have to send the cookies anymore.

Read this article for more info about cookieless domains: http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain

WoLpH
A: 

A CDN is typically spread across the world so that the user is closer to files than if all files were in the main data center.

It is difficult (impossible?) to route a single domain to different data centers.

Also, cookies no longer need to be sent. For Facebook, which has a ton of cookies due to being embedded all over the web, this can be a big saver.

Coronatus
+1  A: 

Stackoverflow itself expains it very well on its static content site.

When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

If your domain is www.example.org, you can host your static components on static.example.org. However, if you've already set cookies on the top-level domain example.org as opposed to www.example.org, then all the requests to static.example.org will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube uses ytimg.com, Amazon uses images-amazon.com and so on.

Another benefit of hosting static components on a cookie-free domain is that some proxies might refuse to cache the components that are requested with cookies. On a related note, if you wonder if you should use example.org or www.example.org for your home page, consider the cookie impact. Omitting www leaves you no choice but to write cookies to *.example.org, so for performance reasons it's best to use the www subdomain and write the cookies to that subdomain.

Originally from Yahoo.

kersny