Reduce Page Weight

Whilst working with SharePoint Master Pages is can be quite common to have to remove ContentPlaceHolders that contain content or controls that aren’t relevant to the design of the site.

If you simply remove the unwanted  <asp:ContentPlaceHolder elements from the master page, you’ll break the site and receive an error when viewing any pages that use your master page.

To work around this is can be quite common to see code that looks something like this used in custom master pages:

<div style="display:none;">
                      <asp:ContentPlaceHolder ID="PlaceHolderPageTitleInTitleArea" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderGlobalNavigation" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderGlobalNavigationSiteMap" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleRightMargin" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBarBorder" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
</div>

In the above example, the unwanted ContentPlaceHolders are contained inside a div that is then hidden via the style attribute "display:none;". The result of this is that the page will render and the unwanted ContentPlaceHolders are not shown to the user.

However, this technique still transfers all the HTML that these ContentPlaceHolders contain down to the client and bloat the page weight with content that is never meant to be shown.

The recommended approach resolving the transmission of unnecessary HTML is to replace the div that is used to hide the unwanted content with a hidden asp Panel that runs server-side. The HTML rendered by the ContenPlaceHolders inside this Panel is never transmitted to the client and the page weight is reduced. This can increase load times and reduce load on the server which is never a bad thing!

The example below show the recommended code:

<asp:Panel visible="false" runat="server">
                      <asp:ContentPlaceHolder ID="PlaceHolderPageTitleInTitleArea" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderGlobalNavigation" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderGlobalNavigationSiteMap" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleRightMargin" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderLeftNavBarBorder" runat="server"/>
                      <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
</asp:Panel>

I hope this helps….