Why so many big and little sites inserts static files (CSS, images, JavaScript, ECC) in a subdomain like media.example.com
or s2.static.example.com
?
What are the advantages? Why not just a directory like example.com/media/
?
Why so many big and little sites inserts static files (CSS, images, JavaScript, ECC) in a subdomain like What are the advantages? Why not just a directory like |
||||
|
I see at least three possible (good) reasons:
That's what is done on StackOverflow if I remember correctly |
||||
|
The primary reason I think, is for cookies. Cookies will be sent along with every request, let's say if you have 2kb of cookie data and load 20 images on a page. That's an extra 40kb of data, multiply that by the number of page-views you have in a month, and you might be surprised about how much bandwidth you have lost in something useless, and bandwidth is not free... Also, cookies set on the top-level domain, are sent across all requests made to any subdomain, in those cases, is even recommended to buy a new domain to host the static components there, in a cookie-free domain. For example, StackOverflow uses Give a look to this: |
||||
|
To add to some of the answers above: some web browsers can only download two files simultaneously from any domain. Serving static content from a different host name (or names - e.g. |
||||
|
This advise was taken from Yahoo's Best Practices for Speeding Up Your Web Site. |
||||
|