ASP.NET Performance: Reducing Size of Web Page | Targetprocess - Visual management software

13 years ago

ASP.NET Performance: Reducing Size of Web Page

We are working on performance improvement and one task is to reduce size of generated HTML pages. For example, user stories list with 20 user stories weight was about 380K, which is too heavy. We've optimized it to 150K using several techniques listed below:

  1. Don't use ID in controls in GridView and Repeater if possible. Each ID (especially in named containers) adds several bytes to each row.
  2. Use shortest possible names in IDs. For example, "wpm" instead "WebPartsManager1". Here is the difference:


    ctl00_wpm_gwpUserStoryList1_UserStoryList1_userStoryGrid_ ctl06_actors_lstActors_ctl02_assignedUsersList_pnlReassignments



    In fact this is one of the most important thing for reducing HTML size

  3. Don't use spaces in ASPX/ASCX code. Use tabs instead (in Visual Studio click Options->Text Editor->HTML->Tabs->Keep Tabs option, then reformat all documents by Ctrl+K Ctrl+D). In fact it is better to remove all tabs in final release at all. Tabs saved us 40K!
  4. Don't use Labels in TemplateField if possible, use just plain Eval or Literal. Each label adds <span></span> around value.
    <asp:templatefield headertext="ID"
     sortexpression="UserStoryID" accessibleheadertext="UserStoryID">
    <%# Eval("UserStoryID") %>

  5. Use IMG instead Image. Image adds often unnecessary style="border-width:0px;" to generated img tag
  6. Do not use inline styles, use classes instead. For example, class="topMenu" smaller than style="padding: 10px; font: 12px Arial; margin-bottom: 10px"
  7. Do not use base.Render() in custom controls that affects states of other controls only. For example, we've used so called Extenders to show/hide other controls based on some input parameters and these extenders rendered as <span></span>, which is just not required.
  8. Use WebParts with care. We've added WebPartsManager into master page and it affected all pages in application. We've moved it into customized pages only.

You can subscribe to our monthly newsletter here:

Thank you!

Сheck out latest blog posts:

Start your free trial

Enter your email
By clicking "Continue", you acknowledge and agree that we will process your personal data in accordance with our Service Privacy Policy and Terms of Service.

We’ve sent you a confirmation e-mail — please, go check it.

Or get a live
product demo