21.6. Saving and Reusing HTML Output
To improve the performance of pages that rarely change, you want to capture the output of those pages and save it for reuse when those pages are requested.
Create the page that contains the desired content as you would any other page, including the server controls you need. At the end of the
Page_Load method, use the
RenderControl method of the
Page control to generate the HTML, and save the HTML to a file.
In the code-behind class for the page, use the .NET language of your choice to:
HtmlTextWriterto use for rendering the page.
RenderControlmethod of the
Pagecontrol to render the output of the page to the
Save the rendered output to a file and redirect to another page.
Occasionally, it’s beneficial to save the HTML output from a generated page. This is commonly done when using the saved HTML can significantly improve web site performance. If the content of a page is static, for example, there is no point in dynamically generating HTML each time the page is requested. Until the advent of ASP.NET, the only way to save the HTML was to use the “Save as Complete Web Page” feature of Internet Explorer or another browser. Though this method does save the HTML, it copies all of the page images to the local machine and changes the image references to point to the local copies. If you ...