1

In HTML5, the script element can be used for data blocks:

The script element allows authors to include dynamic script and data blocks in their documents.

The type attribute gives the MIME type of the content.

If text/html is used, does the script element have to contain a full HTML document? Or are snippets (like in the following example) allowed, too?

<script type="text/html">
  <div>Foobar.</div>
</script>
unor
  • 92,415
  • 26
  • 211
  • 360
  • Ineteresting... And what happens if you run this through the W3C HTML validator? – Mister Epic Oct 02 '13 at 10:52
  • The spec only says, _“[…] and the contents of the script element must conform to the requirements defined for the format used.”_ – but I doubt it would make much sense to deliver a whole HTML document here. And any HTML in there will most likely be problematic in older browsers, so I think I’d rather use text/plain as format, encode any HTML special characters inside it properly, and then parse it afterwards (which in its simplest way could just mean appeding the text somewhere via innerHTML). – CBroe Oct 02 '13 at 10:53
  • @ChrisHardie: It’s valid, but the W3C validator doesn’t inspect the content of `script` elements at all (apart from disallowed characters), in the same way that it doesn’t validate the JavaScript contained in `script` elements. So I can add `
    Foobar`, too, and it doesn’t give me an error.
    – unor Oct 02 '13 at 10:55
  • Well, if you do use a snipped, you are in good company: http://ejohn.org/blog/javascript-micro-templating/ – Mister Epic Oct 02 '13 at 11:03

0 Answers0