aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Prerendering

Open danroth27 opened this issue 8 years ago • 32 comments

Also known as Server-Side Rendering (SSR)

danroth27 avatar Jan 25 '18 17:01 danroth27

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 avatar Feb 07 '18 08:02 gulbanana

@gulbanana Yup that's the the goal.

danroth27 avatar Feb 14 '18 21:02 danroth27

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:

  1. Call Main
  2. Discover all entry components
  3. Find all host tags in static index.html
  4. Instantiate components

LunicLynx avatar Mar 07 '18 14:03 LunicLynx

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.

LunicLynx avatar Mar 11 '18 02:03 LunicLynx

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

Andrzej-W avatar Aug 15 '18 00:08 Andrzej-W

This should also let us return a 404 from the server if it doesn't match any client-side routes.

SteveSandersonMS avatar Sep 13 '18 16:09 SteveSandersonMS

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

Eirenarch avatar Oct 03 '18 12:10 Eirenarch

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!

SteveSandersonMS avatar Oct 03 '18 14:10 SteveSandersonMS

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.

Eirenarch avatar Oct 03 '18 14:10 Eirenarch

@SteveSandersonMS "prerendering" makes more sense.

mrpmorris avatar Oct 04 '18 09:10 mrpmorris

Calling it "prerendering" makes sense and this would allow for Blazor to be use for more then just SPA, e.g. MVC. Web Pages.

A51UK avatar Oct 10 '18 08:10 A51UK

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 avatar Nov 07 '18 14:11 YodasMyDad

@YodasMyDad Yes, I expect so.

SteveSandersonMS avatar Nov 07 '18 14:11 SteveSandersonMS

@SteveSandersonMS fantastic thanks. Will it be OOTB or something you will have to enable?

YodasMyDad avatar Nov 07 '18 15:11 YodasMyDad

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.

Gaulomatic avatar Nov 07 '18 15:11 Gaulomatic

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 avatar Nov 07 '18 17:11 SteveSandersonMS

@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 avatar Nov 07 '18 19:11 Andrzej-W

@Andrzej-W That's the goal

danroth27 avatar Nov 07 '18 19:11 danroth27

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.

A51UK avatar Nov 07 '18 19:11 A51UK

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).

TheGhostFish avatar Nov 09 '18 12:11 TheGhostFish