Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using script tags for client side templates, why can't i load via src attribute?

this works fine (am able to access the snippet in the dom by id)

<script type="text/x-template" id="todo-item-template">
  <div class="todo-view">
    {blah} {blah}
  </div>
</script>

but if i put the template in an external resource, i can't find it in the dom:

<script type="text/x-template" id="todo-item-template" src="todo-item-template.html">

chrome is giving me a warning which i think is irrelevant:

Resource interpreted as Script but transferred with MIME type text/html: 
"http://localhost:8000/todo2/todo-stats-template.html". 

i am running from the filesystem, and/or from python -m SimpleHTTPServer. any ideas?

like image 238
Dustin Getz Avatar asked Jun 11 '26 04:06

Dustin Getz


1 Answers

This is because the server is serving .html files as HTML files. You will want to have template files be a different file type, such as .tpl and have the server send the appropriate headers.

like image 85
Jeff Jenkins Avatar answered Jun 17 '26 19:06

Jeff Jenkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!