【问题标题】:Should I put my mustache template script tags at the bottom of the body like javascript tags?我应该像 javascript 标签一样将我的小胡子模板脚本标签放在正文的底部吗?
【发布时间】:2013-12-27 14:43:00
【问题描述】:

您应该将 JS <script> 标签放在正文的底部以获得最佳性能。我应该对小胡子模板做同样的事情吗?

例如

<html>
  <head>
    ...
  </head>
  <body>
    <h1>Awesome Site</h1>
    <div>
      Bunch of stuff...
    </div>

    <script type="text/javascript" src="awesome-app.js"></script>

    <!-- should I put this here or does it matter? -->
    <script type="text/html" id="mustache-thing">
      <div>
        {{dynamic_stuff}}
      </div>
    </script>
  </body>
</html>

【问题讨论】:

    标签: javascript performance dom mustache


    【解决方案1】:

    是的。原理是一样的:

    允许浏览器先加载DOM,后加载JS

    【讨论】:

    • 为什么对于script 标签的type 不被解释为脚本,而是作为普通数据,这很重要?
    • 仍然是页面加载时不需要放在前面的纯数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    相关资源
    最近更新 更多