Mach-II/Mach-II-Framework — Issue #36: Add asset hosts for HtmlHelperProperty
Author: mpwoodward
Created: 2012-03-01 06:15:02+00:00
State: open
Labels: enhancement

(Moved from http://trac.mach-ii.com/machii/ticket/340)

The concept of this is that modern browsers limit the total number of connections to a domain to 2 at a time (provided that you haven't mucked around with those settings that are usually buried deep). In order to maximize "user experience", you can get around this "issue" by having your assets accessed in different domains. You can easily mock this up by using virtual hosts pointing to a directory. So you might have:

assets01.example.com/js/prototyp.js?123457769790
assets02.example.com/img/css/background_01.png
assets03.example.com/...
assets04.example.com/...
This gets around the total connections because in conjunction with www.example.com -- the browser will treat this like 5 domains and thus have a maximum of 10 connections at once. There is a bit of additional overhead because your system will have to make an additional 4 DNS lookups to resolve assets01-04 subdomains, but in the grand scheme of things this is less of a problems if you are trying to increase speed on an application targeted to broadband users (you probably wouldn't want to do this for a iPhone or BB application where DNS lookups can take a few seconds due to the slow connection).

So what I propose is a way to say that instead of just having all your assets at www.example.com you could configure additional asset hosts (domains). The HTMLHelperProperty would use a "round-robin" like technique based off a hash of the asset path and assign that /js/prototype.js is always served from assets01 etc. so it wouldn't mess up the browser cache by serving that js file from assets04 on the next request. Since the asset host assignment for assets is based off a hash, we can assume that each asset will be served for the same host even if the Mach-II application is reloaded.

Basically the property keeps a map of which assets should be served from which asset host for you and therefore trying to spread asset requests across the total number asset hosts you have.