admin管理员组文章数量:1429858
Simple question: I have a few mustache templates in the front end of the code, many with image tags with a source set to a variable set by mustache js. that is..
<img src="{{img_src}}" />
This is causing the server to load images with a url of root/{{img_src}}, which is unideal. How can I prevent them from being preloaded?
Simple question: I have a few mustache templates in the front end of the code, many with image tags with a source set to a variable set by mustache js. that is..
<img src="{{img_src}}" />
This is causing the server to load images with a url of root/{{img_src}}, which is unideal. How can I prevent them from being preloaded?
Share Improve this question asked Dec 17, 2013 at 4:39 Tim HuiTim Hui 1251 silver badge10 bronze badges 1- This sounds like an XY problem. I think the better question here is: why is the browser receiving (and interpreting as HTML) raw templates? – Matt Ball Commented Dec 17, 2013 at 4:42
1 Answer
Reset to default 7Sounds like you're storing your templates in <div>
s (or similar HTML wrappers) like this:
<div id="t" style="display: none">
<img src="{{img_src}}" />
<div>
If you do things like that, you're telling the browser that your template is HTML when it isn't; if you tell the browser to interpret something as HTML you should expect it to do so. The solution is to use a <script>
container:
<script id="t" type="text/x-mustache">
<img src="{{img_src}}" />
</script>
<script>
s contain non-replaceable character data rather than HTML so the browser won't see the <img>
inside the <script>
as an HTML img
element and it won't try to resolve the src
attribute.
本文标签: javascriptPrevent mustachejs templates from loading images using template syntaxStack Overflow
版权声明:本文标题:javascript - Prevent mustache.js templates from loading images using template syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745495156a2660774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论