I've recently been looking into using JavaScript for templating and I was wondering about the legibility of using this approach.
I understand that JavaScript templating is a very common and much accepted form of templating and I do see the benefits of using this technique.
My question stems more from curiosity as storing HTML text inside a script breaks away from what a 'script' actually is, so to me it feels wrong to do this.
Was JavaScript originally designed to be used as a templating technique when the browser does not understand the type of script? Or was it a trick that people discovered and began to use as HTML text holders for templating purposes?
I've also read that unknown scripts are not processed as scripts and are left as text blocks because of compatibility reasons - so newer browsers can support additional languages without older browsers breaking. Is this maybe the reason for leaving in unknown scripts as text blocks?
I'm trying to understand why browsers behave in the way they do when unknown scripts are found/the intention behind this behaviour.
<script type="application/my-template">Html fragment <i>{{placeholder}}</i></script>
. The browser ignores these contents because it can't handle the mime type for a script. However, the template can be accessed via JS and then rendered dynamically.