Usefulness of Blazor 8 prerendering

207 Views Asked by At

Microsoft states "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".

But there is no easy way to differentiate what is rendered during prerender from what is rendered in the final rendering.

As an example, take a page which fetches data from a database. It could be usefull to render only static content during prerendering and defer database access to final rendering. But there is no simple way to do it. Basically you end up doing the time expensive task (database access) two times, first while prerendering and then again in final rendering.

This has been pointed out already an basically negate any speed or responsiveness advantage prerendering is supposed to bring.

Is prerendering currently an half baked functionality? Any actual real use case for it?

2

There are 2 best solutions below

0
MrC aka Shaun Curtis On

Usefulness of Blazor 8 prerendering

It all depends on your requirements. Just because you don't see a need, doesn't mean that other's don't have one.

There are many, many questions on this very confusing topic. I've referenced two that might be of interest below.

Is prerendering currently an half baked functionality?

No, but it and InteractiveAuto need a government health warning.

[Personal View] You need to really understand what your doing before starting to use them in production. They've been overhyped: everyone seems to jump straight in for the full a la carte option, get into trouble and blame the framework.

See:

Blazor .Net 8 splash screen

How can I get the reference to a component in OnInitializedAsync() - InteractiveServer Mode

How do I share state to be injected across components rendered in different render modes in blazor .net 8?

And a commentary of mine on the overall rendermode topic:

https://github.com/ShaunCurtis/Blazor.ExploreRendering/blob/master/Documents/Going-For-Broke.md

3
corradolab On

Shaun, thank you for your help.

Just because you don't see a need, doesn't mean that other's don't have one.

That's actually my point, I was asking for actual use cases where prerendering proves usefull. Let me summarize what I've learned so far.

RENDER MODE STATIC SERVER

Prerendering does not apply.

RENDER MODE INTERACTIVE SERVER

Prerendering not triggered by interactive routing. This means in most applications it will be triggered only on the first access to the home page.

Inside OnInitialized{Async} you need to know if you are prerendering or not. This is not provided by the framework. Your Blazr.RenderState component does it.

So far the only valid use case seems a Splash Screen, like in your example, which can be done without prerendering anyhow.

Overall I don't see any advantage in using prerendering here.

RENDER MODE INTERACTIVE WEB ASSEMBLY

Prerendering does not apply.

RENDER MODE INTERACTIVE AUTO

This is where prerendering can be usefull, but it comes at a cost.

Like you say, government health warning here: you need to code your components, and all the services they depends on, in a location agnostic way, ie they must work both server side and client side.

How much this adds to the cost while improving user experience is application specific. Probabily worthwhile for a big application with a big budget, probably not for a small one.