What are modern uses of script type="text/html" and is this example considered good use?

According to the HTML5 spec for the script tag, it's totally fine to use <script> with a type attribute set to any valid MIME type. That includes MIME types like text/html or text/plain.

According to the HTML4 spec for the script tag, it's not quite fine:

"There are two types of scripts authors may attach to an HTML document: Those that are executed one time when the document is loaded [and t]hose that are executed every time a specific event occurs"

You don't need backbone for templating. You can use e.g. jQuery or my personal favorite, Mustache.js.


I'm assuming you want to save a portion of HTML to use later. Putting non-script data in a script tag does not make sense. Do what Facebook does!

<code class="hide" id="code1"><!--
  <p>My HTML here</p>
  <script>My Javascript here</script>
--></code>

Then you can grab the HTML later and do whatever you want later:

var html = document.querySelector('#code1').innerText.slice(5, -5)

The scripts inside won't be executed until you handle them properly.

Some notes:

  • No idea what the differences between innerText and other text functions are
  • I don't think you can just insert script tags into the DOM. Not sure how jQuery does it