Jade如何处理src属性? 为什么/ javascripts直接进入文件夹而不是/../public/javascripts?
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实际上在公用文件夹中创buildindex.html? 它是否正确?
第一块玉并不实际上将index.html保存到磁盘,它在请求响应周期中实时生成
第二,默认情况下,express设置为将public/
作为静态文件的根目录,因此您对/javascripts/jquery-2.1.1.js
的引用指向public/javascripts/jquery-2.1.1.js
如果你试图加载/views/index.jade
或/index.jade
它会404,因为Express不会find任何匹配的静态文件
最后是src="/javascripts/jquery-2.1.1.js"
(即用一个前导斜杠)应该是你如何引用它,否则它会根据你的url寻找子文件夹。 (比如,如果您在页面my.domain/parent/child.html
上有js/jquery.js
,请求将转到my.domain/parent/js/jquery.js