David said:
Richard said:
David said:
Yes, this is not anything unique to Rails.
The leading slashes are OK
because they have no significance in SGML syntax.
No, they are OK because the contents of an HTML SCRIPT element
are CDATA and so not mark-up at all, and the contents of an
XHTML script element are PCDAT and so the slashes outside the
<![CDATA[ and ]]> delimiters will be parsed and the (unchanged)
results used as part of the script source code, with the
unparsed contents of the CDATA block inserted in place of the
CDATA delimiters.
That's exactly what I said.
That is not what you said. You said that "The leading slashes are OK
because they have no significance in SGML syntax", and while the leading
slashes have no significance in SGML (which is not necessarily true as
SGML is _extremely_ flexible in which characters and character sequences
may be used as delimiters and/or be significant) it is not this absence
of significance that makes them OK.
There are no shortage of other things that could be included in those
location that have "no significance in SGML" (HTML or XHTML) that would
be anything but OK. Thus the OK-ness here cannot follow form the
insignificance in SGML.
What makes them OK is not that they are not significant to SGML but that
they are in a location where their only significance is to a javascript
parser and they are OK to the javascript parser.
Thanks for reiterating.
Sorry Richard, you're off base on this one.
Don't be so sure. You have not had much practical experience of web
browsers and seem to be inclined to swallow the stories you read on the
Internet without understanding or questioning them.
Remember what I have said here; the <![CDATA[ ... ]]> mark-up is
worthless in an HTML document and the javascript comments are worthless
in an XHTML document.
Case in point: closing
tags in script strings. Consider the following code:
<script type="text/javascript">
//<!--
var myScriptTag = '<script type="text/javascript
src="foo.js"></script>';
//-->
</script>
As we all know, older HTML parses will barf at the
literal closing </script> tag in the string.
All HTML parsers should stop treating the character data as character
That's why you see strings broken up
like:
'<'+'/script' etc.
What I see are character sequences that resemble closing SCRIPT tags
modified into "<\/script>", when I see '<'+'/script>' I am just reminded
that people who don't really understand what they are doing will or why
they are doing it will tend to do things badly, and do introduce the two
unnecessary extra source characters, the runtime overhead of the
concatenation and the two intermediate strings, where one expedient
backslash removes the HTML parsing issue in a way that is invisible
beyond the tokenising of the source code.
so browsers don't mistake this for an HTML element and
parse it mistakenly. (See Flanagan, JavaScript: TDG,
5th Edition, page 247).
Very funnny.
With a CDATA section explicitly defined, this problem
doesn't occur
Nonsense. In HTML it makes no difference. The contents of the HTML
SCRIPT element are already CDATA so the "<![CDATA[" character sequence
will be seen as nothing but a sequence of characters. Thus it will not
modify the interpretation of the character data that follows it and
precedes the ]]> and any occurrences of "</script>" in that data will
still be interpreted as terminating the CDAT content of the HTML SCRIPT
element.
And so, as I said, the <![CDATA[ ... ]]> mark-up is worthless in an HTML
document because in a context that is already CDATA it cannot influence
and coders don't have to worry about this mistake.
If the coders gets fooled into not worrying that would be a problem for
This alone, and the fact that the CDATA tag doesn't
add any other drawbacks over the conventional <!-- -->
comment, make this a preferred approach for commenting
out script sections.
You seem to like declaring things as "preferred". You don't seem too
keen on saying who it is doing this preferring. Obviously they prefer
making up their own excuses for their preferences, rather than having
any genuine technical justification for them.
No round here we 'prefer' that the whole "commenting out script
sections" thing die the death that is now at leas half a decade overdue.
Richard.