ContentPlaceHolder ID and Page Size

We don’t always think about the size of a web page, but when you need the top performance from a web site, you need to consider this aspect too.
I was trying to reduce my page size and I founded some interesting articles about how to remove the ViewState from the page and move it to the user cache (http://www.eggheadcafe.com/articles/20040613.asp) without loosing performance time, or compress javascript files in different way (http://rumkin.com/tools/compression/compress_huff.php; http://www.creativyst.com/Prod/3/; http://www.west-wind.com/WebLog/posts/10294.aspx).
But today I founded something more: how to save page size changing IDs of your controls.
In my pages I have many Repeater and Controls that implements the INamingContainer interface. what does it means? It means that when Asp.Net generate the client side control all the client controls they have a long name made by Parent.UniqueID+"_"+Parent.UniqueID+"_"+Parent.UniqueID+[…]+Child.UniqueID.

[DesignerSerializationVisibility(
DesignerSerializationVisibility.Hidden),
Browsable(false),
WebSysDescription("Control_ClientID")] public virtual string ClientID { get { this.EnsureID(); string uniqueID = this.UniqueID; if ((uniqueID != null) &&
(uniqueID.IndexOf(this.IdSeparator) >= 0)) { return uniqueID
.Replace(this.IdSeparator, '_'); } return uniqueID; } }

So, if one of the parent controls have a long UniqueID, and you have a Repeater inside this control, all the controls inside the repeater will be rendered with a long ClientID.
Just to made an example, I changed on my Default.master
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"/>
to
<asp:ContentPlaceHolder ID="CPH" runat="server"/>
and the page size is decreased from 78K to 75K, 4% of the page size only changing one ID… isn’t it unbelievable??

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s