dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.33k stars 9.97k forks source link

WebAssemblyPreloader component #51989

Open danroth27 opened 11 months ago

danroth27 commented 11 months ago

The interactive WebAssembly render mode will delay downloading and caching the .NET WebAssembly runtime until it's actually needed, but you may want to preload the runtime and cache it for future use. For example, maybe your main app landing page is using static SSR, but other components in the app are interactive. So, you preemptively download and cache the .NET WebAssembly runtime on the main page so it's ready to go for the pages that needed.

You can probably accomplish something like this today by having an empty component on the home page that uses the WebAssembly render mode. This will both download and start the runtime, which may or may not be desirable. We should consider adding a specialized WebAssemblyPreloader component that handles downloading and caching the runtime for future use.

javiercn commented 11 months ago

@danroth27 much simpler than that is to list all the assets in link tags and have the browser download them. It will produce some warnings though if the components aren't used immediately.

The point is, we should rely on standard browser features for this. See https://web.dev/articles/fetch-priority

ghost commented 10 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

javiercn commented 3 months ago

@danroth27 I've been thinking a bit about this.

We can have a Preload component that does the <link rel="preload" ... bit. For example, in the context of a Blazor app, I think we always want to preload the initializers (they are going to run) and when running on webassembly, we likely want to preload the webassembly assets too.

I think we can have something like <Preload Resources="<<some-identifier>> that takes care of locating all the resources associated with that identifier and preloads them.

For example, <Preload Resources="WebAssembly" /> takes care of locating all the webassembly resources and adding a list of link tags to preload them.