How do I code my ASP.NET page to parallelize downloads across hostnames?

心不动则不痛 提交于 2019-12-06 12:35:35

问题


Google Page Speed test tells me I need to distribute my queries across DNS Domain names to speed up rendering.

Since I do development offline, I'd like to find a solution that will distribute my static content (img, CSS, js) across different hostnames, and will still work when I'm offline in an airplane.

Q: How can I code my page to use relative paths (or local host) when offline, and to consistently send static content requests among 5 hosts? After reading this I'd like the url to be similar to this:

When Online: Dynamic content
www.TLSAdmin.com

When Online: Static content
static1.TLSAdmin-Static.com
static2.TLSAdmin-Static.com
static3.TLSAdmin-Static.com
static4.TLSAdmin-Static.com

When Offline: All content
localhost

I'd prefer to make it so that the referred to hostname will be consistent after a page refresh to leverage browser caching. So a random guid.TLSAdmin.com will not be a good idea.


回答1:


How about this:

1) Code all you links to static resources as, for example, [HOSTNAME]/Images/myimage.jpg
2) Create either an HTTP module or a base class for your pages which implements a response filter.
3) That filter should use a regex to find all instances of [HOSTNAME] and replace with an alternative.

The filter could include logic to check if the current hostname is localhost and then just insert localhost as the hostname. To randomise the distribution of the other hostnames whilst maintaining cacheability you could do the following:

1) Have a list of alternative hostnames
2) You'd need a more complex regex/syntax to find [HOSTNAME] and also locate the file name as well
3) Create a hash of the full path of the file. This could be really simple, like counting the ascii codes of each character in the path and finding the module # of hostnames
4) Use the hash value to pick the hostname from the list.

With this, you should get a spread of requests across each hostname + the same resource will always be served from the same host so it can be cached.



来源:https://stackoverflow.com/questions/3653609/how-do-i-code-my-asp-net-page-to-parallelize-downloads-across-hostnames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!