W3C home > Mailing lists > Public > public-html@w3.org > December 2007

<script> for non-script content

From: Philip Taylor <pjt47@cam.ac.uk>
Date: Fri, 21 Dec 2007 22:09:56 +0000
Message-ID: <476C39B4.8010704@cam.ac.uk>
To: HTML WG <public-html@w3.org>

http://quickstarts.asp.net/Futures/ajax/doc/components.aspx uses
   <script type="text/xml-script">
for embedding XML which gets interpreted by some other JavaScript code. 
No UA could ever process that XML natively like a proper script, since 
it would conflict with the JS's handling of the XML.

   <script ... type="x-shader/x-fragment">
for embedding OpenGL shader programs. It would never make sense for a 
browser to execute the code directly, since it only works in the context 
of a complete OpenGL environment.

http://lists.w3.org/Archives/Public/public-html/2007Dec/0238.html says 
"we use the <script> tag with a Backbase MIME type" as a container for XML.

But http://www.w3.org/html/wg/html5/#script just says "The script 
element allows authors to include dynamic script in their documents", 
and does not acknowledge the use of <script> as a non-executable 
container for text which has an associated MIME type and can be read by 
other scripts.

Since this is something that people want to do, we should suggest a 
proper way to do it. XHTML makes it fairly easy, but it's harder for the 
HTML serialisation. I think the main requirements are:
(1) Works in current / recent web browsers.
(2) Does not require escaping of the content (else it's ugly and hard to 
edit when writing HTML by hand).
(3) Does not impose any restrictions on the content.
(4) Does not get rendered by web browsers.
(5) Does not require complex scripting magic to extract the content as a 

<xmp> is not perfect for (1), since Opera 9.2 has parser bugs that make 
it not work. It is not perfect for (4), since you need to say "xmp { 
display: none }" instead of it working by default.

<xmp> and <script> are not perfect for (3), since they don't allow the 
content to contain the strings '</xmp' or '</script'.

Any new element is useless for (1) or for (2) or for (5), since it won't 
work sensibly in all significant current browsers.

I don't know of any other sensible solutions for this problem. <script> 
fulfils most of the requirements, and the one it fails is not a critical 
issue since most content will not try containing '</script>' and almost 
all embedded content types will have some kind of equivalent (e.g. 
programming languages with '"<\/script>"' or XML with '<foo:script 

In the absence of a better solution, and in the interest of paving the 
cowpath (i.e. adopting people's current solution to the problem), 
<script> should be accepted for this use, and defined like:

   "The script element allows authors to include dynamic script in their 

    It may also be used to embed arbitrary textual data in the document 
when user agents are not expected to execute that data, for example to 
be processed by another script. In this case, the type attribute must be 
present and set to a MIME type for which user agents probably won't ever 
implement support. [That last sentence is rubbish, but something similar 
should be said.] XHTML documents should not use the script element in 
this way, as techniques such as namespaces and CDATA sections allow 
better solutions."

Philip Taylor
Received on Friday, 21 December 2007 22:10:07 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:29 UTC