Multiple Asset Hosts

Hey there,

I’ve been wondering if the assumption of four asset hosts for the sake of speed improvements is still valid.

Rails documentation about asset hosts:

Browsers typically open at most two simultaneous connections to a single host, which means your assets often have to wait for other assets to finish downloading. You can alleviate this by using a %d wildcard in the asset_host. For example, “”. If that wildcard is present Rails distributes asset requests among the corresponding four hosts “”, …, “”. With this trick browsers will open eight simultaneous connections rather than two

According to this (, browsers are supporting typically 6 - 8 simultaneous connections per host nowadays. However, there’s an average max connection limit of 2 times of that.

Would it make sense to adjust the behaviour to generate only two asset hosts by default?



## On Perf Changes

Any performance improvements that have wide implications such as this, need to be benchmarked before they could be merged.

It’s not enough to do the research, we would need actual experimental proof that it works, provides a significant speed boost to justify the extra code costs and doesn’t have any major downsides.

If you add a new feature, it has to be tested. If you do a perf change, it needs to be benchmarked. It’s not good enough to shoot in the dark

## On multiple asset hosts

You can do this today. Rails accepts a proc for the asset_host that you can use to randomize an asset host however…

I looked into this extensively in the last 6 months and the general consensus is that it doesn’t help much, and even then it can make performance slower. Most connections are fast these days, but the overhead in making new connections is still there. Basically the browser doesn’t know that www.domain and www1.domain are the same and must connect separately. The result can be a slower page render.

Go ask igrigorik, he knows this stuff backwards and forwards (browser behavior and speed). Here’s two good articles

## However

If you feel strongly, go test it. Build up repeatable benchmarks and instructions for others to run them. Don’t take my word on this, test it.

Domain sharding is still useful but our guidance is outdated. It's from a pre-SSL-everywhere, pre-SPDY era where browsers had low per-domain connection caps.

(TIL that chrome will "unshard" SPDY requests to different hosts with the same IP and SSL cert!)

The other thing to consider is that the connection overhead is much, much higher for mobile. If you have a responsive site and/or a high proportion of mobile visitors performance may be much worse for these visitors when using asset domains.