The said:
I'm interested in this bit - I tend to comment freely so what is the
now-accepted way to add comments?
It was *never* accepted coding style to use markup comments as script
comments. As Rob has pointed out, you have been relying on a proprietary
feature which has never been safe on the Web. (In case you wonder, examples
in specifications are never normative.)
Since there is no working user agent that requires those pseudo-comments in
order to prevent the code from being displayed (in a nutshell: UAs should
never display `head' element content as if it were in the document body in
the first place; HTML 3.2 standardized the `script' element, and HTML 2.0
was marked obsolete; in HTML, the content model of the `script' element is
CDATA, not PCDATA), and they can do harm (it's a non-standard feature of UAs
or script engines to ignore them; in XHTML, the content model of the
`script' element is PCDATA, not CDATA), you can safely remove them in old
*HTML* documents and omit them in new ones.
As for XHTML, there is only one possibility of a comment requirement within
the `script' element content, and that is if you want to serve so-called
HTML-compatible XHTML as text/html to UAs that don't support XHTML, and as
application/xhtml+xml to UAs that do (that would be relying on
error-correction, though, which in itself is error-prone), and your script
code contains one or more of `<', `>', and `&':
<script type="text/javascript">
// <![CDATA[
// script code goes here
// ]]>
</script>
However, as Rob also has pointed out, the alternative is to refer to
external script resources. While that is recommended by the W3C (XHTML 1.0
Appendix C, section 4), I don't think it should be considered a general
recommendation. Another script resource not only separates script code and
the elements it is working on, which complicates maintenance, but also
requires another HTTP connection which is overkill, if it is only a small
script (for fitting values of "small").
I also wonder why you feel it is a bad idea to serve XHTML as HTML.
See for example:
http://www.spartanicus.utvinternet.ie/no-xhtml.htm
http://hixie.ch/advocacy/xhtml
However, note that the necessity to use `<!--//--><![CDATA[//><!--' and
`//--><!]]>' that Ian mentions is based on the assumption that there were
working user agents out there that would not support the `script' element.
But as I have pointed out before and on numerous other occasions, that
notion is outdated now as it already was when this advisory was created/
last modified. I consider pointing that out to Ian via private e-mail.
After all, if we serve it as XHTML it buggers things up on the browser
end half the time.
Quite the opposite is true.
http://www.w3.org/2000/07/8378/xhtml/media-types/results
You would be well-advised to use the Google Groups archives of this
newsgroup before posting; this has been discussed several times already.
PointedEars