Jade如何处理src属性?为什么/javascripts会直接进入文件夹,而不是/./public/javascrip


doctype html
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
        script(src="/javascripts/jquery-2.1.1.js")
        script(src="/javascripts/global.js")
    body
        block content

显然,src="/../public/javascripts/jquery-2.1.1.js"不起作用,但src="javascripts/jquery-2.1.1.js"起作用

文件结构如下:

nodetest
  public
    javascripts
      jquery-2.1.1.js
  views
    index.jade

除非Jade实际上在公共文件夹中创建index.html ?这是正确的吗?

first jade实际上并没有将index.html保存到磁盘上,而是在请求响应周期中动态生成的

其次,express默认设置为将public/作为静态文件的根目录,因此您对/javascripts/jquery-2.1.1.js的引用指向public/javascripts/jquery-2.1.1.js

如果你试图加载/views/index.jade/index.jade,它会404,因为Express找不到任何匹配的静态文件

和最后的src="/javascripts/jquery-2.1.1.js"(即以斜杠开头)应该是你引用它的方式,因为否则它会根据你的url寻找子文件夹。(例如,如果页面my.domain/parent/child.html上有js/jquery.js,则请求将转到my.domain/parent/js/jquery.js

)

最新更新