To add to what Brad and squadette have said, the self-closing XML syntax <script />
actually is correct XML, but for it to work in practice, your web server also needs to send your documents as properly formed XML with an XML mimetype like application/xhtml+xml
in the HTTP Content-Type header (and not as text/html
).
However, sending an XML mimetype will cause your pages not to be parsed by IE7, which only likes text/html
.
From w3:
In summary, 'application/xhtml+xml' SHOULD be used for XHTML Family documents, and the use of 'text/html' SHOULD be limited to HTML-compatible XHTML 1.0 documents. 'application/xml' and 'text/xml' MAY also be used, but whenever appropriate, 'application/xhtml+xml' SHOULD be used rather than those generic XML media types.
I puzzled over this a few months ago, and the only workable (compatible with FF3+ and IE7) solution was to use the old <script></script>
syntax with text/html
(HTML syntax + HTML mimetype).
If your server sends the text/html
type in its HTTP headers, even with otherwise properly formed XHTML documents, FF3+ will use its HTML rendering mode which means that <script />
will not work (this is a change, Firefox was previously less strict).
This will happen regardless of any fiddling with http-equiv
meta elements, the XML prolog or doctype inside your document -- Firefox branches once it gets the text/html
header, that determines whether the HTML or XML parser looks inside the document, and the HTML parser does not understand <script />
.