My company hosts about 30 web sites all sharing the same code base and reusing many of the same images. Right now, the images for all of the sites are hosted on the one domain, and then every other site has to link to those images.
i.e., www.exampl开发者_高级运维e.com/images/hello.jpg
and on www.example2.com we have something like:
<img src="http://www.example.com/images/hello.jpg" />
Recently someone told me that I should be putting all of these shared/static images on a subdomain, but I don't see the advantages to this. I have heard that there might be a slight speed increase, but I've also heard that it can complicate things. Can someone elaborate?
A couple advantages to it:
- A separate domain prevents your domain's cookies from being sent for every image request, where they're not needed. Reduces the bandwidth overhead for each request.
- Most browsers will only make a certain number of HTTP requests at one time to a particular domain, so serving images and other static content off a second domain potentially doubles the number of HTTP requests at one time.
- You can conceivably use a different, lighter weight webserver like nginx/lighttpd to serve the static content.
Downsides:
- Managing it.
- Two DNS lookups instead of one.
When a browser is requesting static files like CSS and Javascript, it often limits the number of connections to a given server/sub-domain. Putting static files under a different domain allows more simultaneous downloads.
If set up correctly, the different sub-domain may just be a directory on your webserver. Depends on your config-file-fu.
This is covered in a couple of the Stackoverflow podcasts.
One concern - if you are serving an https page the user may get a warning about a mix of secure and insecure items.
精彩评论