简体   繁体   English

我们可以使用Angular 2的服务器端预呈现来代替服务器模板引擎吗?

[英]Can we use Angular 2's server-side pre-rendering in place of server templating engine?

I am a student, and still very new to web development. 我是一名学生,对网络开发仍然很陌生。 Recently, I have come across angular 1.x, react.js, and angular 2 (Ultimately decided to land on angular 2). 最近,我遇到了角1.x,react.js和角2(最终决定落在角2)。

One thing that have hung in my mind lately is server-side pre-rendering. 最近我脑海中浮现的一件事是服务器端预渲染。 In my thought, this server-side pre-rendering is doing the job of server template processor (Like jade.js. I haven't tried it though). 在我看来,这个服务器端预渲染正在完成服务器模板处理器的工作(就像jade.js.我还没试过它)。 The difference is that the js templating code can be reused on client-side. 不同之处在于js模板代码可以在客户端重用。 Is my understanding correct? 我的理解是否正确? Does it mean that we can use angular 2 or react in place of other templating engines? 这是否意味着我们可以使用角度2或代替其他模板引擎进行反应?

Angular 2's server-side rendering isn't replacing a templating engine. Angular 2的服务器端渲染并没有取代模板引擎。

Server-side rendering lets you write your Angular 2 code as you normally would (with or without something like jade). 服务器端渲染使您可以像往常一样编写Angular 2代码(使用或不使用jade之类的东西)。 The server renders the first page the user will see, so the user isn't looking at a blank page while the javascript loads. 服务器呈现用户将看到的第一个页面,因此用户在加载javascript时不会查看空白页面。 This decreases perceived page load times and makes the site more accessible to web crawlers. 这减少了感知的页面加载时间,并使网站爬虫更容易访问网站。

This video shows how you would implement server-side rendering in Angular 2. There are some links to starter repos in the comments. 此视频显示了如何在Angular 2中实现服务器端呈现。注释中有一些启动回购的链接。

Angular 2 Universal is the server rendering project that is developed PatricJS and Jeff Wepley. Angular 2 Universal是PatricJS和Jeff Wepley开发的服务器渲染项目。 Here is the maintained project in git. 这是git中维护的项目。 It's a starter seed for new comers. 它是新来者的入门种子。

Here (SystemJS) 这里(SystemJS)

For WebPack 对于WebPack

For usage: 用法:

git clone https://github.com/angular/universal-starter/
git checkout systemjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM