[Source Index] | [Feedback]
|
1.Allows the insertion of notes into the source document that will not be displayed by the HTML client.
2.Allows for the hiding of cetrain features by browsers that don't support those features (most notably to hide Scripting from browsers that don't support a particular scripting language.
1. <!--This is a comment-->
2. <SCRIPT Language="YaddaScript">
<!--
[script type stuff goes here]
[this is inside a comment tag
to hide it from browsers that
don't support YaddaScript]
-->
</SCRIPT>
Comments are often very useful in situations where many people will be editing the document, or in situations where the author wishes to make notes for future reference.
In long, complicated docments, placing comments at the beginning of blocks that need to be changed often can be used to make these blocks easier to find.
Keeping a history of what was changed, by whom, and when is a helpful practice when dealing with many documents that require different types of updating. This is most efficiently done by including that revision history in comments near the top of the document.
Comments are loaded with the file and add to the file's overall size. Keep this in mind when commenting. Every thousand characters (approximately) adds another kilobyte of data.
There is another usage for text stored in comments, influencing search engines. Some search engines will index words hidden in comments (and thus assign a higher relevance to certain pages during in response to certain queries). This practice is no longer effective on its own. In fact, the major search engines has developed filters to catch such 'keyword stuffing' and will penalize sites that abuse comments in this way.
According to SGML comment syntax rules, a comment element starts with <!, followed by zero or more comments, followed by >. A comment starts and ends with "--", and does not contain any occurrence of "--".
This means that these are also legal SGML comments:
While example 3 is a waste of typing, it's still a legal comment.
Getting tricky with your comments can possibly lead to large sections of your document not showing up due to the number of hyphens telling the browser that the comment is not finished.
To make it easier on yourself (some clients aren't very good with parsing strict HTML much less SGML), always think of an HTML comment beginning with <!--, ending with --> and not containing any extra --'s or >'s anywhere in the comment.
You may find other instances of the <! beginning that would seem to suggest that which follows is a comment.