what is server side rendering using angular2?

巧了我就是萌 提交于 2019-12-08 17:09:59

问题


I am aware that angular2 is used for server side rendering. So I would like to know more about it.

I am having following questions regarding this phenomenon.

1.What is server side rendering?

2.what problem does it solve?

3.what are its applications?

4.why server side rendering used?

5.what are the technologies that support server side rendering?

6.in angular2, what goals server side rendering helps to accomplish?

7.what are the main differences between client side & server side rendering?

8.which tools or frameworks can be used for server side rendering ?

Thanks to all in advance.


回答1:


Angular2 is client library and it's not used for server side rendering. There is, however, a project Angular Universal that aims to allow server to process angular code and templates.

1. In general Server Side Rendering /SSR/ refers to using a server to create content that could be consumed by the browser (or other clients).

2. With Single Page Applications /SPA/, like Angular2 apps, one of the big issues is initial load. SPAs have to load all vendor and app scripts, (maybe load content from database,) process the content, and finally render it. This can take a lot of time, so the idea is that you use SSR to create or "prerender" the initial page.

3. It's used because servers are faster then clients, so it can be big performance boost for applications. Also it's helpful with search engine robots - when they request a page of your website without SSR they would see only blank page without any content (some search engines would load and execute your scripts).

4. Angular Universal works on nodejs servers. I believe there is also a version for PHP, but it's very fresh (in alpha I think...)

5./6. see above.




回答2:


1) Server side rendering renders views already on the server, before it is delivered to the client. This means things like data binding expressions are already resolved on the server and the resulting HTML is delivered to the client so it can be shown by the browser immediately instead of executing JS first.

2) - faster time from load to fist display
- SEO

3) see 2)

4) - Angular2
- React AFAIK
- probably lots of others

5) see 2

6) the former renders on the server, the later on the client :p To be able to render on the client the code needs abstraction of the browser and the server code needs to generate HTML like it would be done by the browser. In Angular this is done by completely abstract the browser away (this also makes it easier to enable the application to run in WebWorker because there the code also doesn't have (or only has limited) access to the browser API)




回答3:


Though the question is addressed twice & beautifully, I just wanted to add on few things for user still coming to it.

  • SSR majorly address the abstraction & faster and safe content delivery to Browser.

  • Things like State\Session management, User accounts management, passwords\tokens used for web services, Payment Gateway details are the things you would like to avoid putting on browser\client side.

  • Main technologies\frameworks to address this issue are: MEAN.IO MEAN.JS, express.js, nodes.js, meteor.js

  • If you are from .net world then MVC is the best fit to keep a well plumed framework.

Hope this sherds more light on it.

Danke.



来源:https://stackoverflow.com/questions/35552842/what-is-server-side-rendering-using-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!