Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I progressively render a header before content in ASP.NET master pages?

I have a large slow ASP.net site that uses master pages.

I've identified that the user will have a better experience if they can see the header and navigation while the rest of the page is being generated/processed/loaded from the database.

I've done some simple tests and I can do Response.Write() followed by Response.Flush() in page_load(), and IIs will use chunked encoding and send the output to the browser immediately while the rest of the page renders.

I want to do the same thing, but only send the master page header and navigation.

Any pointers on how to achieve this?

Using ASP.net 4 and IIs 7.5

Edit

If anyone can give some pointers on how to change the site to use AJAX without having to change every page and link, I'd appreciate it. Thanks!

like image 723
Byron Whitlock Avatar asked Apr 28 '11 23:04

Byron Whitlock


2 Answers

If you flush the response stream at some point manually and do not manually set the content length it will enable chunked encoding.

This question seems related: How can I set Transfer-Encoding to chunked, explicitly or implicitly, in an ASP.NET response?

And this blog post talks about response flushing and chunked encoding: http://www.rahulsingla.com/blog/2010/06/asp-net-sets-the-transfer-encoding-as-chunked-on-premature-flushing-the-response

like image 102
sclarson Avatar answered Sep 28 '22 19:09

sclarson


I suggest you use control caching. Asp.Net provides native caching of pages and controls. See these links to know more.

ASP.NET Caching: Techniques and Best Practices

http://msdn.microsoft.com/en-us/library/aa478965.aspx

ASP.NET Caching

http://msdn.microsoft.com/en-us/library/xsbfdd8c(v=VS.100).aspx

Control caching

As you have mentioned, it appears that you already use page-caching. Try using control-caching to further improve the caching. To use control caching, place PartialCachingAttribute over the control class. You can use the ControlCachePolicy of the control to set caching behavior:

control.GetCachePolicy()
like image 37
Miguel Angelo Avatar answered Sep 28 '22 20:09

Miguel Angelo