2 suggestions

Apr 2, 2010 at 7:16 AM
Edited Apr 2, 2010 at 7:18 AM

Hi

 

thanks for your great component, it's just what I want in my project, two suggesgions:

 

1) If I have 10+ css/js files in my page, user have to wait a long time for the 1st request when the remote resource files are being downloaded synced from remote server (eg cdn) by webclient.DownloadData, could you provide an option to download file async using webclient.DownloadDataSync()?

2) Could you provide a function to dynmaic collect all resource in one request including mater page aspx page and ascx user control and treat them as one resourceset?

eg after I set a lot if <cc:Include> tags in my front-end page, this custom control will add all these urls to HttpContext.Items and in http endrequest event it automatically package them to one resourceset and appent it to page without any config in xml file. Furthermore, if we can have an option in config file to enable this auto function for some page is much better.

looking forward to your reply   : yzhu@live.com

Coordinator
Apr 3, 2010 at 11:02 AM

Hi!  Thanks a lot for your suggestions.  These are great suggestions.

Regarding #1, I understand the issue that the 1st request is slow, but I'm not sure how DownloadDataAsync() can help make the request any faster though.  The server still needs to wait until the download is completed to return full content to the browser.  Or do I misunderstand anything?  Anyway, I suppose adding support for a more persistent cache than ASP.NET cache will help (see this http://combres.codeplex.com/WorkItem/View.aspx?WorkItemId=5523).

Regarding #2, this is a good idea.  There are a couple of related feature proposals (http://combres.codeplex.com/WorkItem/View.aspx?WorkItemId=5606 and http://combres.codeplex.com/WorkItem/View.aspx?WorkItemId=6253).  I need to think of a design to harmonize all these. 

 

Apr 3, 2010 at 1:08 PM

Hi,

 

#1 I mean, will it be faster if the handler download all these resources parallelly by multiple threads? eg

 

class ResourceHandler : IHttpHandler
    {
        private StringBuilder data = new StringBuilder();
        private int finished = 0;
        private object locker = new object();

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            string key = context.Request.QueryString["url"];
            if (string.IsNullOrEmpty(key)) return;
            List<ResourceItem> items = RawResourceCache.Data[key];
            if (items == null) return;

            foreach (var item in items)
            {
                WebClient wc = new WebClient();
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
                wc.DownloadStringAsync(new Uri(item.Url), item.Url);
            }

            while (finished != items.Count)
                Thread.Sleep(100);
            context.Response.Write(data.ToString());
        }

        private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            lock (locker)
            {
                finished++;
                data.AppendFormat("/******** {0} ********/{1}{2}{3}", e.UserState.ToString(), Environment.NewLine, e.Result, Environment.NewLine);
            }
        }
    }

 

#2  another approach is to provide a gui tool to analyze all the aspx ascx and export the resources settings to your config file :)

 

thanks  , Ye

Coordinator
Apr 4, 2010 at 9:36 AM

Thanks for your suggestions.  Parallel download is definitely something I want to have.  #2 is an interesting idea;  maybe the GUI tool can even do more, like allowing edit the config as well.  I've created 2 new tickets for these items so that I can prioritize them among other things I'm working on.  Thanks again!