node.js - 讨论一下前端开发模式
ringa_lee
ringa_lee 2017-04-17 14:48:44
0
1
632

目前有两种方案:

1.node作为前端服务渲染页面,页面写的是后端模板。用node跟服务器php进行交互。
2.node+react,node作为服务端只提供服务,页面由客户端渲染,交互逻辑也是写在react组件中,根据react的0DOM操作会提高页面的渲染速度。
请大家各抒己见,来探讨一下这两种开发模式哪种比较好,请说出原因。

ringa_lee
ringa_lee

ringa_lee

reply all(1)
PHPzhong

Both methods have their own application scenarios. Let’s briefly talk about their respective 优缺点 and 适用场景.

Method 1

node serves as a front-end service to render the page, and the page is written as a back-end template. Use node to interact with the server php.

Advantages:

  1. Friendly to page SEO: The page is well rendered on the server side, which is more beneficial to SEO.

  2. The first screen appears faster: node and php interact, assuming they are deployed on the same machine, it is local communication, the speed is fast, and the corresponding 获取数据-> 渲染页面 -> 返回页面 time is faster than the second option.

Disadvantages:

  1. Two implementations: The same rendering logic may need to be implemented once on the server side and the browser side.

  2. Higher service quality and reliability: The server-side logic is relatively heavy, and the quality and reliability guarantee requirements have gone up.

Applicable scenarios: Such as news portals, blogs, etc.

Method 2

node+react, node as a server only provides services, the page is rendered by the client, and the interaction logic is also written in the react component. The 0DOM operation of react will increase the rendering speed of the page.

Advantages:

  1. Front-end and back-end decoupling: the server is responsible for providing data, and the client is responsible for view rendering, making it more maintainable.

  2. No need to implement it twice: it has been mentioned above and will not be repeated. As for the benefits brought by react itself, I will not expand here.

Disadvantages:

  1. Not friendly to SEO: With this solution, the page returned to the front end is mostly just a skeleton, and the content has not been filled in, so the SEO effect will not be very good.

  2. The first screen rendering speed is slow: React is a big guy. In addition, 加载js(包括react)-> 拉取数据 -> 渲染组件 Compared with option one, the speed is generally slower because there are more network back and forth.

Applicable scenarios: Sites that focus on business operations and have a lot of interactions. Such as management backend and rich client applications.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template