Hi @David Thielen ,
Advantage of ServerPrerendered:
Prerendering is the process of initially rendering page content on the server without enabling event handlers for rendered controls. The server outputs the HTML UI of the page as soon as possible in response to the initial request, which makes the app feel more responsive to users.
Besides, in 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. It is a trade-off: Blazor pre-renders page and sends it as a static page, then later the page becomes an interactive Blazor server app. This behavior is intended to serve pages quickly to search engines with time-based positioning.
Calls OnInitializedAsync()
twice:
In Blazor Web App 8.0 : Prerendering is enabled by default for interactive components.
You can disable prerendering for a component instance, pass the prerender
flag with a value of false
to the render mode: <... @rendermode="new InteractiveServerRenderMode(prerender: false)" />
Or avoid reading the DB twice, reading appropriate data from the database once during prerendering. Restore the data when the component is rerendered.
Advantage of InteractiveServer:
Blazor Web App 8.0 project template: we’ll get a Blazor app which is wired to render components statically on the server by default. If we need our components to be more interactive, we run the component in Interactive Server mode. Interactive Server mode is an easy way to enable interactivity for our app.
It’s easy to take an existing component (that is being rendered statically) and switch it to use Interactive Server. In most cases it’s simply a case of setting the rendermode
attribute for the component.
Because the component is still running on the server, we don’t need to introduce a Web API for handling requests (our components can call business logic and/or connect to data directly).
As of .NET 8, Blazor server circuits are disconnected automatically when no longer needed. In this case, if we navigated to different page with no interactive server components the underlying socket connection would be disconnected after a short time, thereby reducing the load on the server.
Interactive server-side rendering (interactive SSR) renders the component interactively from the server using Blazor Server. User interactions are handled over a real-time connection with the browser. The circuit connection is established when the Server component is rendered.
You can have a look at Prerender ASP.NET Core Razor components and ASP.NET Core Blazor render modes to know more.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Qing Guo