简体   繁体   中英

Load html content of master page in next pages

I have a requirement where i want to increase the performance of the page because my master page is heavily loaded with controls taken from the database.

I want to save the HTML output of the master page so that i can use the HTML for loading to other pages which uses the master page thus reducing the time taken for loading the page.

Is it possible.? if possible any reference.

I searched for same online but could get some irrelevant content.

Use Asp.Net Output Caching You can cache entire pages or page fragments (usercontrols).

ASP.NET allows you to cache some or all of the response generated by an ASP.NET page, referred to in ASP.NET as output caching. You can cache the page at the browser making the request, at the Web server responding to the request, and at any other cache-capable devices, such as proxy servers, that are in the request or response stream. Caching provides a powerful way for you to increase the performance of your Web applications. Caching allows subsequent requests for a page to be satisfied from the cache so the code that initially creates the page does not have to be run again. Caching your site's most frequently accessed pages can substantially increase your Web server's throughput, commonly measured in requests per second.

Thisi is a small example just to explain how it works:

in order to cache a page's output, use the @OutputCache directive at the top of the page:

<%@ OutputCache Duration=5 VaryByParam="None" %>
  • Duration - The time in seconds of how long the output should be cached. After the specified duration has elapsed, the cached output will be removed and page content generated for the next request. That output will again be cached for 5 seconds and the process repeats.
  • VaryByParam - This attribute is compulsory and specifies the querystring parameters to vary the cache. To specify multiple parameters, use semicolon or * for all parameters passed through the querystring

you can increase the performance of ASP.net Application by using caching feature

you can increase the cache of master page by adding in following lines in masterpage cs file

protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
        Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
        Response.Cache.SetValidUntilExpires(true);
    }

saving html is not a good idea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM