Lazy loading of application areas
@danroth27 Do you already have a few more details available for how this might work on a conceptual level? E.g. is it envisioned that each lazy-loaded area could be in a separate project/assembly?
I'm always interested in scalability beyond the typical demo projects used at conferences and in tutorials... ;-)
And another aspect that I believe is of interest to people with existing systems: Is there a way to support a hybrid solution, e.g. an ASP.NET MVC application with some parts implemented using Blazor?
Is this the wrong question and/or does this warrant creating a separate issue?
Perhaps I'm asking to fly to the next galaxy while you guys are trying to just get launched into space in the first place....
@ManfredLange Nothing to share on the design for lazy loading quite yet.
As for ASP.NET MVC, you can use Blazor with any backend that you'd like including non-.NET back ends like Java, JavaScript, PHP, etc, although we make it particularly easy to use Blazor with ASP.NET Core. However, Blazor today takes full ownership of the app and the DOM, so you can't really use MVC to render some HTML on the server and then use Blazor to manipulate the DOM on the client. We are however looking at server-side pre-rendering support for Blazor.
@danroth27 link above broken. here's the fixed version server-side pre-rendering, I wish GitHub let you do it the way you tried though. You have to put [24] in brackets rather than [#24]
@mungojam Thanks! Fixed
@danroth27 I am not sure, but does it means that Lazy loading will solve this kind of problem? Can it be coupled with "Mozilla HACKS" about WebAssembly?
@ckams Lazy loading is about being able to break your Blazor app up into multiple areas that can be loaded independently. It's Blazor specific, so not related to ASP.NET Core MVC and server-side rendering. You do get the perf benefits of WebAssembly in the browser.
@danroth27 I'm not sure I understand. Sorry :s Is Lazy loading like Application Parts? Can Lazy loading be used to load multiple areas in WebAssembly from server-side?
Is Lazy loading like Application Parts?
Nope
Can Lazy loading be used to load multiple areas in WebAssembly from server-side?
Yes, lazy loading allows you to load different areas of your app client-side from the server as needed. It's similar to lazy loading in frameworks like Angular or React.
I don't see target release. Any idea in which release this feature will be available?
@abhishekgoenka Sorry, but we don't know when this feature will land quite yet.
I'm imagining two levels of lazy loading: page level and component level. This will allow the Blazor team to deliver in phases, whichever is easier first (perhaps page level?).
At page level, the entire page is lazy loaded. Thus, in an app, a page's assembly is only loaded to the browser until the user clicks on the page's link. A page would have to be declared as lazy (ex. @lazy "appname.pagename.wasm").
At component level, the component can be declared @lazy "appname.componentname.wasm". In this sense, the component's assembly will be loaded only when the page that needs it is loaded.
Thus, the @lazy directive can be used by the engine to generate different wasm's that can be "plugged in" to the client at runtime upon request (via page and/or component that needs it). I'm thinking WebAssembly's dynamic linking comes to play here (if I'm understanding it correctly)? Or perhaps Blazor will provide the mechanism to allow it?
@danroth27 would it be possible to get any news regarding ETA of lazy loading?
@hokusp Unfortunately there isn't any news to share at this point. This feature is on our backlog, but we don't expect to get to it any time soon. Our current thinking is that Lazy Loading is not critical for shipping Blazor v1.0. We still want to support it though, and we expect it would ship in a follow on release.
To help us ensure that we are prioritizing this feature correctly, it would be great if folks could share with us more details on how you expect to use this feature and why it's important for your scenarios.
Just because Dan asked 👍
In my opinion, Lazy Loading is essential for Blazor to be able to provide a good support for PWAs and a faster web experience in general.
My use case for lazy loading is simply that any page containing its most usable components should be able to be presented to the user within a max of 2 seconds from first visiting the site. This means that both pages and components should be able to be identified as lazy-loaded. Along with lazy loading a page, it would be great if an already loaded page could hint on the next page/components to be loaded and like this triggering a pre-fetching or nav pre-loading mechanism. PWAs can use Service Workers to do pre-fetching but that would not play nicely with Blazor app if no APIs are provided to facilitate it through Blazor.
For my current project, it would be great if I could load Blazor components as independent modules. I have a website where different modes will be added over time and those modes should not be coupled to the "mainproject", it should be possible that different independent people develop them and that they can be added to the site without redeploying the whole site. I imagine it a bit like an API controller: There is a request to the server /GetAppMode("identifier") and it then loads the module "identifier" and returns it to the client.
As for lazy loading, lazy dlls (library projects in general) should be the easiest ones to implement. With this approach, splitting the app in multiple assemblies will simply mean that a request for the dll is made the moment it's required, not before. Then, you could use standard .NET functions like GetAssemblies, GetReferencedAssemblies, etc to know which assemblies (modules) are already loaded.
I don't know a lot about the implementation in this area, sorry if what I'm saying doesn't make sense.
This is one of the key must-have feature that is missing and keeping us away from adapting Blazor. The concept of representing Areas (https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-2.2) as lazy-load modules would be a good approach. Until this feature is added, it is hard to consider Blazor for medium to large size enterprise applications.
Please consider this as a priority feature.
@danroth27 are there any updates on this?
Thanks for this feedback, @ganu81! This feature isn't going to fit in .NET Core 3.0, but we will consider it as part of our post-3.0 planning.