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 ( without loosing performance time, or compress javascript files in different way (;;
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.

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"/>
<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??

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s