有什么区别
@(await Html.RenderComponentAsync<Todo>(RenderMode.ServerPrerendered))
和
@(await Html.RenderComponentAsync<Todo>(RenderMode.Server))
我正在查看文档,但找不到真正可以解释差异的内容。并且也不太理解枚举上的代码注释:
// Summary:
// Renders a marker for a Blazor server-side application. This doesn't include any
// output from the component. When the user-agent starts, it uses this marker to
// bootstrap a blazor application.
Server = 2,
//
// Summary:
// Renders the component into static HTML and includes a marker for a Blazor server-side
// application. When the user-agent starts, it uses this marker to bootstrap a blazor
// application.
ServerPrerendered = 3
幕后发生了什么? 使用 Server 与 ServerPrerendered 的场景是什么?
最佳答案
解释于ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 9 :
- Static Statically render the component with the specified parameters.
- Server Render a marker where the component should be rendered interactively by the Blazor Server app.
- ServerPrerendered Statically prerender the component along with a marker to indicate the component should later be rendered interactively by the Blazor Server app.
这个概念与性能相关。提供页面的最快方法是静态渲染页面然后发送,而提供页面的最慢方法是提供“交互式 Blazor”服务器页面(通过 SignalR websockets 同步实时虚拟 DOM)。
ServerPrerendered
是一种权衡:Blazor 预渲染页面并将其作为静态页面发送,然后该页面成为交互式 Blazor 服务器应用程序。此行为旨在通过基于时间的定位快速向搜索引擎提供页面。
关于c# - blazor 中的 RenderMode.Server 和 RenderMode.ServerPrerendered 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58229732/