Being primarily a server-side web developer, my exposure to JavaScript has been limited to externally referenced files and event handlers with minimal initialization functions between <script> tags.
Recently, I discovered that the data within <script> tags is not typically escaped and cannot be escaped without causing issues for the JavaScript parser in all browsers. This realization brought to light the challenge of using CDATA for in-HTML JavaScript blocks to pass validation in XHTML.
As someone who values encoding and escaping standards, I find this exemption from HTML escaping rules for <script> (unlike JS-event handlers such as onclick
) puzzling. Why was this decision made? Was it a result of historical development or a deliberate choice?
The same inconsistency applies to CSS and the <style> tag. Is there a specific reason behind these exceptions, or has the rationale been lost over time?