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

4

11

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!

Advance answered 28/4, 2011 at 23:59 Comment(6)
Is there anything you can do to make the page smaller? Maybe turn off viewstate where possible, etc?Hightest
A far better solution would be to profile the pages, find where they block (I guarantee it's in a database call) and then offload those database calls to to be either asynchronous or use AJAX to load them independent of the page content. Caching the calls may also be sufficient depending on what it is.Disloyalty
@Chris Well I'd do that, but it isn't one database call. It is a whole shebang of stored procedure calls (written by our dba) that really can't be optimized much more without sharding the db or something. There is caching in place, but with so many pages most of the time it doesn't help. While using AJAX would be ideal, I am not sure how to do that without re-architecting the whole site. (Let me know if there is simple way to do this!!!) Remember, this site has hundreds of pages with tens of different master pages based on client. This is not a simple site.Advance
Bryon from what you've said you already NEED TO re-architect the entire site. You've hit performance boundaries that are by the inherent design of your application. Even if you succeed with the goal that this question intends it clearly doesn't SOLVE your problem it just buys you more time to address it. It sounds like you've just reached the point of failure in your current design and it's time to start over with new design and start replacing pieces of your application that are the biggest value winners. I'd rewrite the new pieces in MVC3, you could also cheat and just iframe it in the siteDisloyalty
What do you mean by using ajax... I see two meanings: 1) after page loads, automatically load other pieces of the page using ajax. 2) when user clicks something, use ajax to change a piece of already loaded page. I think you were talking about the first... am I correct? In that case an UpdatePanel WILL NOT solve your problem... in the second case it does solve the problem quite seamlessly.Menes
@Miguel Angelo - Update panel, nice. make that an answer and you just earned 250 rep sir.Advance
M
2

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()
Menes answered 5/5, 2011 at 18:55 Comment(1)
The bounty ends in 10 minutes and you had the most useful answer, but not to my question. Grats.Advance
M
3

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

Memling answered 29/4, 2011 at 2:45 Comment(1)
I already know that I can call Response.Flush() to set chunked encoding. I just need to be able to call Render() before the main content is populated somehow. I need to render the master page header and footer.Advance
M
2

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()
Menes answered 5/5, 2011 at 18:55 Comment(1)
The bounty ends in 10 minutes and you had the most useful answer, but not to my question. Grats.Advance
E
2

I would suggest tracing the page, and try to figure out why exactly the page is rendering slow. The following might help...

http://www.dotnetscraps.com/dotnetscraps/post/How-to-troubleshoot-issues-with-Page-Rendering-in-ASPNET.aspx

And use DIVs in place of TABLEs!

Regarding AJAX usage, AFAIK... there is no shortcut. You can use AJAX script manager in your master page, and use the script manager proxy to the pages where you want to ajaxify the page. Change your Form to introduce an Update panel and you should be good for most pages.

Emblem answered 6/5, 2011 at 9:45 Comment(0)
N
2

This might be helpful to you. I alway use yslow for FF alongwith firebug to check out the performance.

https://addons.mozilla.org/en-us/firefox/addon/yslow/

https://addons.mozilla.org/en-US/firefox/addon/firebug/

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

http://developer.yahoo.com/performance/rules.html

Thanks

Neidaneidhardt answered 7/5, 2011 at 7:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.