Html Jade如何处理src属性?为什么/javascripts直接进入文件夹而不是/public/javascripts?
显然,Html Jade如何处理src属性?为什么/javascripts直接进入文件夹而不是/public/javascripts?,html,node.js,express,pug,Html,Node.js,Express,Pug,显然,src=“/../public/javascripts/jquery-2.1.1.js”不起作用,但src=“javascripts/jquery-2.1.1.js”起作用 文件结构如下所示: doctype html html head title= title link(rel='stylesheet', href='/stylesheets/style.css') script(src="/javascripts/jquery-
src=“/../public/javascripts/jquery-2.1.1.js”
不起作用,但src=“javascripts/jquery-2.1.1.js”
起作用
文件结构如下所示:
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
除非Jade在公用文件夹中实际创建index.html?这是否正确?首先,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
nodetest
public
javascripts
jquery-2.1.1.js
views
index.jade