Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
66
|
第
7
章
document.querySelector('#error').innerHTML =
'<div class="error"><h3>Error</h3>' +
'<p>Something <b><a href="/error-detail/' + errorNumber +
'">very bad</a></b> ' +
'happened. <a href="/try-again">Try again<a>, or ' +
'<a href="/contact">contact support</a>.</p></div>'
我就会建议采用模板了。关键在于,当决定如何在
HTML
字符串和使用模板之间划清界
限时,我期望你能培养出良好的判断力。不过对我来说,宁可选择模板,也要避免使用
JavaScript
生成
HTML
,除非是最简单的情形。
7.2
 选择模板引擎
在
Node
的世界中,有很多模板引擎可以选择。那么该如何选择呢?这是一个很复杂的问
题,很大程度上取决于你的需求。不过,下面给出了一些考量标准。
性能
显然,你希望模板引擎尽可能地快,不想看到它拖慢了网站。
用于客户端、服务器端,还是两者中均用?
大多数(但不是全部)模板引擎可用于客户端和服务器端。如果需要使用前后两端均可
用的模板(你需要使用),则建议选择两端都可以处理的模板。
抽象程度
你是想要一个熟悉一些(例如,就像正常的
HTML
,只是多加了一些花括号)的
,还
是有些讨厌
HTML
,更喜欢摆脱那些尖括号的模板呢
?模板化 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099