RenderMode.Server 和 RenderMode.Server 在 blazor 中预渲染有什么区别?
What's the difference between RenderMode.Server and RenderMode.ServerPrerendered in blazor?
有什么区别
@(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.
这个概念与性能有关。最快的页面服务方式是静态呈现页面然后发送,而最慢的页面服务方式是服务 "interactive Blazor" 服务器页面(通过 SignalR websockets 同步实时虚拟 DOM) .
ServerPrerendered
是一种权衡:Blazor 预呈现页面并将其作为静态页面发送,然后该页面稍后变为交互式 Blazor 服务器应用程序。此行为旨在通过基于时间的定位快速将页面提供给搜索引擎。
ServerPrerendered 的主要问题是它加载了两次,因此您的数据层代码也执行了两次。 服务器模式还可以,可能会慢一点。
有什么区别
@(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.
这个概念与性能有关。最快的页面服务方式是静态呈现页面然后发送,而最慢的页面服务方式是服务 "interactive Blazor" 服务器页面(通过 SignalR websockets 同步实时虚拟 DOM) .
ServerPrerendered
是一种权衡:Blazor 预呈现页面并将其作为静态页面发送,然后该页面稍后变为交互式 Blazor 服务器应用程序。此行为旨在通过基于时间的定位快速将页面提供给搜索引擎。
ServerPrerendered 的主要问题是它加载了两次,因此您的数据层代码也执行了两次。 服务器模式还可以,可能会慢一点。