ASP.NET – Simple Page Load Improvement #1...
While doing some development, I came up with a small slick-trick that I would like to share. Maybe I’m just slow to the game and you’ve already thought of this, or are doing this. Regardless, one way to improve page load time is to decrease the amount of content sent to the requesting browser. Search engines often consider load time as a factor in ranking page results. Because of this, getting your page size as small as possible can yield a return on investment. At the same time, if you get carried away, an ASP.NET page can become difficult to maintain.
One way to keep your page maintainable is to include comments. This includes both HTML and JavaScript comments. When you use HTML and JavaScript comments though, your page size increases (just a small bit). In addition, your page viewers really don’t care about the comments. Because of this, it doesn’t really add any value to them. The comments are purely there for the individuals maintaining the page. The question then becomes, how do I skip sending comments to the client, but still have them for development purposes?
The answer is server-side comments. Server-side comments prevent a code block in an ASP.NET page from being processed and rendered. Because it is not rendered, it does not get sent to the client page. For instance, compare the following two small blocks.
| Before (size: 308 bytes) |
<div>Hello! How are you? The time is <div id='ds'></div></div></script> |
| After (size: 214 bytes) |
<div>Hello! How are you? The time is <div id='ds'></div></div></script> |
The sizes mentioned above represent the size of the content actually sent to the browser. As you can see, using server-side comments gave us a ~30% savings! While your typical savings will generally not be this high, it still proves the point that you can help your users load the content quicker and help save bandwidth costs.

