Home | Contact Us

CSharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript

ASP.NET Server-Side Comments

This page looks at examples of ASP.NET comment syntax. Server-side comments are removed before the page is sent.

Server-side comments. HTML comments waste bandwidth.

We can instead use server-side comments. We can comment .aspx files with ASPX comments—this restricts the debugging information and comments to the development environment, improving efficiency.

Comments. Here I introduce ASP.NET server-side comments. Not only that, but I offer some uses that are not widespread but can make your site stand out from its competitors. First, let's look at a couple comments in an .aspx file.

HTML comment example

<!-- HTML comment
     Will bloat every page sent to browsers
     Makes your site super-slow. -->

ASPX comment example

<%-- ASPX comments
     Uses percent sign
     Removed at compile-time
     Doesn't increase size of markup
     You can even optimize with them. --%>

As we know, each .aspx page is compiled into a control tree. As this happens, ASP.NET removes server-side comments—such as the second one above. When the browser receives the page, the markup would look like the next sample.

Note: The second comment above was removed. If a visitor downloads the page, only the HTML comment will come through the wire.

Result of above two examples

<!-- HTML comment
     Will bloat every page sent to browsers
     Makes your site super-slow. -->

Discussion. I observed something else interesting with server-side comments. They can make your web page smaller, but they can also speed up server-side processing. This is because ASP.NET constructs a control tree for each page.

Also: You can remove whitespace from the pages, which would be turned into Literal controls.

When applying server-side comments, I reduced the number of Literal controls on every page by at least 10. These comments improved performance, made the pages smaller, and reduced the complexity of the control tree on the server.

Summary. We used server-side comments in ASP.NET web page markup, which is mainly found in ASPX files. We noted how the server-side comments are removed during processing and do not show up in the client-side pages.

Finally: We noted some performance details and uses of server-side webpage comments.