Search code examples
htmlasp.netserver-sideperformance

HTML Markup in an ASP.NET website (Writing code efficiently)


I have seen a lot of debate regarding this on the web and would like to know if anyone has any specific facts on the subject.

QUESTION

When writing an ASP.NET based website, in terms of performance and efficiency, is writing client side code better than writing server side code when no server side requests or code behind are required?

EXAMPLE

<div id="abc">SOME TEXT</div>
<a id="hyp" href="home.aspx"></a>

VS

<asp:Panel ID="abc" runat="server">SOME TEXT</asp:Panel>
<asp:HyperLink ID="hyp" runat="server" NavigateUrl="Home.aspx">SOME TEXT</asp:Panel>

Both will render the exact same markup in the browser. It seems counter intuitive as the amount of code actually wrote is greater however I have read several arguments that using asp markup allows for faster processing of the page at run time.


Solution

  • In terms of performance and efficiency, is writing client side code better than writing server side code when no server side requests or code behind are required?

    Yes, the first example can certainly lead to more efficient HTML.

    Older versions of ASP.NET will produce automated html Ids, that tend to be quite long.

    If you had a page with a lot of these automated Ids the page-size could be far bigger than a page where the Ids are carefully hand-crafted.

    A larger page size will obviously take longer to download.