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

让人想犯罪 __ 提交于 2019-12-14 03:52:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13939084/using-script-tags-for-client-side-templates-why-cant-i-load-via-src-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!