title | author | description | monikerRange | ms.author | ms.custom | ms.date | uid |
---|---|---|---|---|---|---|---|
Prerender ASP.NET Core Razor components |
guardrex |
Learn about Razor component prerendering in ASP.NET Core Blazor apps. |
>= aspnetcore-8.0 |
riande |
mvc |
11/08/2022 |
blazor/components/prerender |
This article explains Razor component prerendering scenarios for server-side Blazor apps.
Prerendering can improve Search Engine Optimization (SEO) by rendering content for the initial HTTP response that search engines can use to calculate page rank.
Important
This article is currently undergoing updates for .NET 8. Please check back periodically for new content or when .NET 8 is released.
Important
This section is currently undergoing updates for .NET 8.
Without persisting prerendered state, state used during prerendering is lost and must be recreated when the app is fully loaded. If any state is setup asynchronously, the UI may flicker as the prerendered UI is replaced with temporary placeholders and then fully rendered again.
A large prerendered state size may exceed the SignalR circuit message size limit, which results in the following:
- The SignalR circuit fails to initialize with an error on the client: :::no-loc text="Circuit host not initialized.":::
- The reconnection dialog on the client appears when the circuit fails. Recovery isn't possible.
To resolve the problem, use either of the following approaches:
- Reduce the amount of data that you are putting into the prerendered state.
- Increase the SignalR message size limit. WARNING: Increasing the limit may increase the risk of Denial of service (DoS) attacks.
- State management: Handle prerendering
- Razor component lifecycle subjects that pertain to prerendering
- Component initialization (
OnInitialized{Async}
) - After component render (
OnAfterRender{Async}
) - Stateful reconnection after prerendering
- Prerendering with JavaScript interop
- Component initialization (
- Authentication and authorization: General aspects
- Handle Errors: Prerendering
- Host and deploy: Blazor Server
- Threat mitigation: Cross-site scripting (XSS)
- xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync is executed twice when prerendering: Handle asynchronous navigation events with
OnNavigateAsync