Quantcast

Comments in HTML: Who Needs ‘Em!

Get the WebProNews Newsletter:
[ Business]

The other day, I was fixing a client’s HTML web page that was failing to display some essential elements, like header tables, in Netscape 6.2. After a quick inspection, the problem popped right out of the page: they were using invalid comments to document the HTML script.

Here is an example of one of the comments:

<!—- Script Starts Here —————————>

Normally, a comment won’t raise any problems in ANY browser. However, Netscape’s strong adherence to the HTML standard allows little room in the way of sloppy code. So, let’s take a look at what the standard says about comments.

The Standard

First of all, zero or more comments can exist within the ‘
<!– Comment –> <!– Comment 1 — – Comment 2 — – Comment 3 –> …or even… <!>

In terms of white space between ‘–’ in each comment, the standard states that it is allowed after each comment but not before the first. In other words,

<!– Comment –!>
<br> <br>
is allowed, but not
<br> <br>
<! — Comment –!>
<br> <br>

Looking back at the first example that was giving my client fits, we can now deduce what the problem was. At first glance, no doubt it probably seems peculiar. After all, there are a lot of ‘–’ without
any text between. But, the standard doesn’t necessarily require any text to exist within a comment. Though it may not seem useful,
there’s nothing wrong with <!—-> .

The real problem lies in the fact that some comments are started, but never finished. Take a look at the following simplified example:

<!– Comment —->

Now we can count how many comments actually exist within this element. ‘– Comment –’ is one, then we start another with ‘–’, but never end it! Netscape frowns upon such deviant behavior.

Code Bloaters

It’d be silly for me to argue against the use of commenting code; after all, comments have been used in hundreds of computers languages over the last 50 years! However, the simple fact is that HTML comments do increase file size and are of no particular use to users visiting your web site. Before you go ripping them out of your web pages, make backups! So, instead of having no documentation in your scripts or sending needless data to visitors, you can compromise. This allows you to efficiently transmit web pages–saving time for your users and costly bandwidth for your ISP–while having a copy of fully documented code to easily reference at any time.

This is similar to how a programming language like C++ handles the situation. The author can keep a copy of the fully documented source code while distrubiting optimized machine code to his or her users.

Everybody wins!

iEntry provides free highly informative newsletters for web developers, IT professionals and small business owners. We deliver 50 million email newsletters per month and have over 4,000,000 unique opt-in subscribers. From our extensive range of email newsletters we can provide you with a selection of newsletters that best meet your interests.

Comments in HTML: Who Needs ‘Em!
Comments Off
About Web Development Writer
iEntry provides free highly informative newsletters for web developers, IT professionals and small business owners. We deliver 50 million email newsletters per month and have over 4,000,000 unique opt-in subscribers. From our extensive range of email newsletters we can provide you with a selection of newsletters that best meet your interests. WebProNews Writer
Top Rated White Papers and Resources

Comments are closed.