Prerendering
Also known as Server-Side Rendering (SSR)
is this issue about the feasibility of server side rendering? in a perfect world, the app assemblies could be netstandard-based, capable of rendering html in an asp.net core server which is then hooked up to the live client code in mono-wasm
@gulbanana Yup that's the the goal.
I would like to get my feet wet on this, but I'm not quite sure how to tackle this.
For example there is the BasicTestApp in the Repo. Which does nothing in Program::Main or nothing of importance.
To make use of prerendering for this App we would need to go about this the same route as with angular and the other spa frameworks. Host nodejs, load mono.wasm and so on. Which in my opinion should not happen.
Probably the BrowserRenderer should not be called directly at all. The purpose of the main method should only be for setting up DI and maybe telling the execution environment which component is the entry component and which selector belongs to it. Which could also be done with an attribute of some sort.
Workflow would look something like this:
- Call Main
- Discover all entry components
- Find all host tags in static index.html
- Instantiate components
I started some prototyping on this. https://github.com/LunicLynx/Blazor/tree/prerendering For now it only generates the html for the root component.
Missing
- Return the rendered html in the first request
- Render / Insert the html into the index.html
This is quick and dirty
Some interesting ideas
- Provide different implementations for services on the server side. This would allow to make api calls directly to the services without making an http request.
Please remember about SEO (prerendering different elements in <head> section for each route). More about this here: https://github.com/aspnet/Blazor/issues/1311#issuecomment-413046895
This should also let us return a 404 from the server if it doesn't match any client-side routes.
In my opinion this feature is super important. Accidentally this is what the SPA world (React/Angular/Vue) means when they say Server Side Rendering. Blazor means something else
I totally agree this is important. It's something we've had planned from the beginning.
We've never intended for Blazor's server-side execution mode to be called "server-side rendering". Some people in the community have used that phrase for it, but I would regard that as a mistake. We will not use the term SSR for server-side Blazor. We recognize that SSR is different.
Regarding SSR, I personally prefer the term "server-side prerendering" or just "prerendering" because it's more clear that the server-side part is just a one-time render, after which client-side code has to take over if it's going to be interactive. Same is true for Angular/React/etc. That's why this issue title is "prerendering". Hope that makes sense!
Yes, it makes sense. I've been trying to find out if you guys are working or at least tracking this feature but any search is stomped by the server-side execution mode results. Luckily a nice guy on reddit pointed me to this issue.
@SteveSandersonMS "prerendering" makes more sense.
Calling it "prerendering" makes sense and this would allow for Blazor to be use for more then just SPA, e.g. MVC. Web Pages.
Is this feature likely to be in the first release of Razor Components in .Net Core 3.0? Would be great to have Blazor apps be crawl-able by Google etc..
@YodasMyDad Yes, I expect so.
@SteveSandersonMS fantastic thanks. Will it be OOTB or something you will have to enable?
It might not be the right place here, so excuse me in advance. I wanted to thank @SteveSandersonMS for his work, basically being the 0.8 percent of all ASP.NET staff working directly on Blazor - as shown in the last ASP.NET community standup. Thanks for making this very enjoyable way of developing web apps possible, a whole bunch of people really like this work.
Thanks @Gaulomatic - that's great to hear! Also I'd add that @rynowak @danroth27 @javiercn from the ASP.NET team have done a lot of the work, plus 20% of our commits are community PRs so you're all to thank too!
@SteveSandersonMS It is great that prerendering is planed for Razor Components v1.0! Unfortunately I'm one of those Blazor fans who prefer client side version. Can we assume or at least have hope that prerendering will work equally well in that version also?
@Andrzej-W That's the goal
I am one of blazor fans that would like more of a mix of server side and client side. I would love to be able to use blazor on asp.net core MVC or Web Page to replace JavaScript. An example of this is a foreach loop that rendering the first 10 item on server side and blazor take over on the client side (e.g. add new item, updates, pagination). I do not really like SPA.
Blazor is a Great and Easy way to create Admin Panels .. It lowers development time to the 1/4 .. Pre-Rendering is required to be set for front-end SEO, And we should have the option to enable/disable it per Area (ie disable pre-rendering in Admin Panel and enabling it outside).