什么是 javascript 的服务器端渲染?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16173469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is server side rendering of javascript?
提问by Aravind Yarram
Some javascript frameworks like Dust.js claim that they ALSO support server-side rendering (in addition to client side rendering) as well. Can someone explain how does this work? My understanding is that the JS is always executed in the browser runtime.
一些像 Dust.js 这样的 javascript 框架声称它们也支持服务器端渲染(除了客户端渲染)。有人可以解释这是如何工作的吗?我的理解是 JS 总是在浏览器运行时执行的。
采纳答案by chrx
JavaScript can be run on servers using systems like Node.js.
JavaScript 可以在使用Node.js 等系统的服务器上运行。
With regard to Dust.js, a templating engine, it can generate hypertext and HTML on the server and send that content directly to the client's browser. This is typically used to avoid a flash of temporarily empty templates, caused by the browser requiring a split second to populate a view's templates via a framework like Dust.js. The downside is that the page will take slightly longer to load because more work has to be done on the server before sending data to the client.
关于Dust.js模板引擎,它可以在服务器上生成超文本和 HTML,并将该内容直接发送到客户端的浏览器。这通常用于避免由于浏览器需要瞬间通过 Dust.js 之类的框架填充视图模板而导致的临时空模板的闪烁。缺点是页面加载时间稍长,因为在将数据发送到客户端之前必须在服务器上完成更多工作。
Check out this questionfor the pros and cons of server-side rending. One must choose between slow post-processing (requiring the user's browser to do the work) or slow pre-processing (making the server do the work before the user sees anything).
查看此问题以了解服务器端渲染的优缺点。必须在缓慢的后期处理(需要用户的浏览器来完成工作)或缓慢的预处理(让服务器在用户看到任何东西之前完成工作)之间做出选择。
回答by VirtualAbi
Server side rendering is converting JavaScript into static html and css. Earlier JS tended to load last to optimise website performance. But the problem was it affected SEO. So server side rendering became the solution to resolve this issue.
服务器端渲染正在将 JavaScript 转换为静态 html 和 css。早期的 JS 倾向于最后加载以优化网站性能。但问题是它影响了搜索引擎优化。所以服务端渲染成为解决这个问题的方案。