Are CDATA tags ever necessary in script tags and if so when?
In other words, when and where is this:
CDATA indicates that the contents within are not XML.
That way older browser don't parse the Javascript code and the page doesn't break.
Backwards compatability. Gotta love it.
When browsers treat the markup as XML:
<script>
<![CDATA[
...code...
]]>
</script>
When browsers treat the markup as HTML:
<script>
...code...
</script>
When browsers treat the markup as HTML and you want your XHTML 1.0 markup (for example) to validate.
<script>
//<![CDATA[
...code...
//]]>
</script>