3

How can I cache the master page in ASP.NET?

Sauron
  • 16,668
  • 41
  • 122
  • 174
  • What do you mean by caching the master page? They are never sent to the client, so can't be client-side caching, and as they are combined when compiled/run into the pages that use them, it's not server-side. *confused* – Will Dec 09 '09 at 05:44
  • Becoz My master page contains a tool bar and having large number of images in it. – Sauron Dec 09 '09 at 05:53
  • So you want client-side caching to prevent frequent reloading of static images, yea? – o.k.w Dec 09 '09 at 06:05

2 Answers2

2

Unlike user controls, you can't OutputCache a Master page by itself--only as part of a Page.

Also, OutputCaching won't help the performance of a toolbar with lots of images anyway.

The kind of things that would help include image sprites, client-side caching, using a CDN, using multiple domains for static files, etc.

In case it's helpful, I cover those strategies in my book: Ultra-Fast ASP.NET.

RickNZ
  • 18,448
  • 3
  • 51
  • 66
  • In which portion of the book you covered that things. Please make reply – Sauron Dec 18 '09 at 03:40
  • I cover client-side performance issues in Chapter 2 (pages 13 to 70), including optimizing your HTML structure, optimizing network use with multiple subdomains, image sprites, etc. Then I cover caching in Chapter 3 (pages 71 to 126), including caching at all tiers: client, proxies, server kernel (http.sys), IIS, output caching, fragment caching, etc. There's also a section on Master Pages and User Controls in Chapter 6. The whole book is focused around performance tips; I'm sure other chapters will also be useful. – RickNZ Dec 18 '09 at 03:56
  • Definitely your book is very much useful. Thanks for such a book. – Sauron Dec 18 '09 at 04:00
  • @RickNZ: Thanks for the reply. I have another question based on your reply: if the master page contains text displaying the user name logged on to the application and if the Page is cached, won't the same cached version of the Page + Master display to other users (potentially)? What technique can be applied to NOT cache the master page portion within the Page but cache only the Page contents? And thanks for linking to your book, it looks very useful. – narayan Dec 30 '13 at 06:52
  • User-specific content on a Master page will indeed normally be cached. You can work around that issue using either Ajax or cookies (set from other URLs). If the amount of unique content is large, other caching techniques may be more appropriate (fragment caching, and so on). – RickNZ Dec 30 '13 at 12:12
1

If you use the @OutputCache directive on the page that uses the master page, then the master page will be cached along with the rest of the page.

Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110