【问题标题】:Does The Placement of JS Scripts in Pug and Jade Files Matter?Pug 和 Jade 文件中 JS 脚本的放置是否重要?
【发布时间】:2018-06-01 03:44:19
【问题描述】:

为什么当我们这样放置行时页面加载速度更快:

script(src="/Scripts/jquery.timeago.js")

在我们的标签末尾而不是在

说:

//Jade file with JQuery
!!! 5
html(lang="en")
  head
    title Holamundo!
    script(type='text/javascript', src='http://code.jquery.com/jquery-1.9.1.js')
  body
    h1#headTitle Hello, World
    p#content This is an example of Jade.
    script
      $('#headTitle').click(function() {
        $(this).hide();
      });
      $('#content').click(function() {
        $(this).hide();
   });

【问题讨论】:

    标签: javascript html node.js express pug


    【解决方案1】:

    Pug 模板会被转换成 HTML,发送到浏览器。

    无论它是如何生成的(手动、通过 pug 模板或其他系统),浏览器都会以相同的方式解释 HTML 输出。

    因此,您的问题最终是这个:Where should I put <script> tags in HTML markup?

    延伸阅读:How exactly does <script defer="defer"> work?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2018-02-17
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2015-05-03
      • 2016-10-28
      相关资源
      最近更新 更多