Vault of Thoughts

2006-07-04

Please visit my new blog at vaultofthoughts.net

Optimizing rendered page size

I do not often rename the controls that I do not use in the code behind code, so when I place a Label on a page it most often is named something like Label1. It does not make a big difference when you are not paying for the bandwidth and you only have a few controls on a form. Imagine however that you are working with Master Page and there you are using the defaul ContentPlaceHolder1 as a place for pages to put their contnet. Now it is only 19 characters long yes? But when you look at the generated html, you will see that each control put on a page using such a Master Page has its ID prefixed with the ID of the placeholder. A quick calculation on one of my pages and It appeared that for 100 controls on a page I was wasting 2000 characters only for the id of the placeholder!!! Just renaming the placeholder from the default ContentPlaceHolder1 to something like CPH saves 1700 characters. Such a name change does not cause any major inconvinience on the developer's part since you will rarely reference the placeholder by its ID.


The same mechanism holds true especially for controls such as GridView and UserControls which tend to have a long ID.


Currently I'm renaming all my controls that I put inside a GridView or FormView templates to one letter strings since I'm not using them. I also rename all my controls on pages to a shortest string that I can come up with without loosing the meaning.


kick it on DotNetKicks.com

If you liked this article why not support its author by making a donation?

1 Comments:

  • I've never thought about it before. On the other hand, how often do you have 100 server controls on a webpage anyway, but ofcourse, sometimes you do. Good tip.

    By Anonymous Mads Kristensen, at 10:46 PM  

Post a Comment

Links to this post:

Create a Link

<< Home