布局自定义vs使用两个布局 – expressjs
比方说,我有一个主要layout.handlebars
和一个网站有两个主要部分。 如果我自定义layout.handlebars
,会有任何性能差异:
<head> <title>{{title}}</title> <link href="css/bootstrap.css" rel="stylesheet"> {{#if section1}} <link href="css/section1.css" rel="stylesheet"> {{else}} <link href="css/section2.css" rel="stylesheet"> {{/if}} </head>
像这样呈现:
router.get('/section1', function(req, res){ res.render('section1',{title: 'Section 1', section1: true}); });
而不是使用两个不同的布局,每个网站的两个部分?
没有性能的影响,但你会最终得到混乱的代码。
如果“第3部分”出现怎么办? 另一个如果?
关于什么
<head> <title>{{title}}</title> <link href="css/bootstrap.css" rel="stylesheet"> <link href="css/section1.css" rel="stylesheet"> <link href="css/section{{section}}.css" rel="stylesheet"> </head>
渲染它像这样:
router.get('/section1', function(req, res){ res.render('section1',{title: 'Section 1', section: "1"}); });
要么
router.get('/section2', function(req, res){ res.render('section2',{title: 'Section 2', section: "2"}); });