c# - blazor 中的 RenderMode.Server 和 RenderMode.ServerPrerendered 有什么区别?

标签 c# .net blazor blazor-server-side

有什么区别

@(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/

相关文章:

c# - 在代码中引用 XAML 元素时出现 WPF NullReferenceException

c# - 如何从给定的父节点获取所有子节点?

c# - 清空列表<string>

c# - 将Blazor从3.1升级到5.0时出错 "does not have a property matching the name ' PreferExactMatches'“

c# - 项目中不存在目标 "PreComputeCompileTypeScript"

c# - 为什么在移位 32 位值时只使用移位操作数的低五位? (例如(UInt32)1 << 33 == 2)

c# - Azure移动服务.NET后端HttpResponseMessage返回null内容

.net - 无法批量加载,因为无法打开文件 “"。操作系统错误代码5(访问被拒绝。)

blazor - 是否有一种 blazor 方法来模拟 html 元素上的点击事件?

blazor - 当 ASPNETCORE_ENVIRONMENT 更改为 "Development"以外的任何内容时 - 在 VS 中调试时,Blazor 应用程序看不到来自 razor 类库的资源