One difference between good and bad code are comments. Good programmers tend to comment their code to make it readable for themselves (the next day ;-) ) or for other programmers (*).
There are situations though where one doesn't want comments to show up - like in an ASP.NET Web Application. Imagine the following simple app.
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
// This function does something
// incredible :-)
function DoSomethingIncredible() {
alert('Hallo');
}
</script>
</head>
<body onload="DoSomethingIncredible()">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label" /><br />
<!--
Don't need this currently but
am not sure if I need it in
the future... You get my point ;-)
<asp:Label ID="Label2" runat="server" Text="Label" />
-->
</div>
</form>
Unfortunately the comments will be send down to the client together with the remaining markup.
Fortunately ASP.NET supports a little known feature called “server-side comments” (<%-- --%>) which removes comments on the server. Check out the enhanced code...
<%--
--%>
...together with the new output (behold the missing comments...). Pretty sweet, eh?
Enjoy!
Daniel
* O.K. Fair enough. This statement only holds true for the somewhat good programmers. The really 1337 programmers naturally don't need no 1@m3 comments ;-)
PingBack from http://geeklectures.info/2008/01/14/server-side-comments-or-how-to-automatically-remove-htmljavascript-comments-from-websites/
Server Side Comments or how to automatically remove HTML/JavaScript comments from websites ...