.Net Blazor WebAssembly sounds really great. It can run fully client-side, meaning there is no need for a dynamic server and one can even host it on a CDN. Even better, it is possible to turn it into an installable PWA. So I looked at some demos and was horrified to find out, that loading an example page on synfusion.com approximately took me 15 seconds with a decent internet connection.
Here is the example: https://blazor.syncfusion.com/showcase/wasm/health-tracker/

I do absolutely understand, that the entire .Net Runtime for Webassembly needs to be downloaded and that this naturally takes some time, and I have already measured, that the time on subsequent loads, when the runtime for the page is already cached, is "only" about 3 to 5 seconds.
This however is still a lot, and in my opinion unusable in a real life secnario. Which user is going to wait for a website that takes 15 seconds to load?

所以我的问题是,肯定有一种内置的方法来缩短启动时间.也许人们只能加载.Net运行时的那些部分,这些部分是主页或用户请求的任何页面工作所必需的.我理解这一点,这可能很困难,因为.NET运行时很可能是非常相互关联的,并且大多数部分将依赖于其他部分.我可以想象,在下载WebAssembly运行时之前,首先会提供一个传统的HTML/Js/css页面.也许至少可以显示尚未交互的用户界面,给用户一种速度感?另外,为什么后续加载要花费3秒以上的时间?运行时应该被缓存,从缓存中检索它真的需要那么长时间吗?

如果有人知道如何在.Net Blazor WASM应用程序中改善启动时间,我会很高兴听到解决方案,因为默认的启动时间长得令人无法忍受,至少对我来说,这不适用于任何现实世界的场景,这真的是一种巨大的耻辱.

PS:
I of course have also tried to built my own page and measured the initial startup time and the cached one, which both are faster than the syncfusion ones, but of course the application is also way smaller in size, when compiled and built.

啊,是的,对于任何想要一个最小可重现示例的人来说,以Visual Studio中的Web应用程序模板为例,将其配置为Interactive Render模式=WebAssembly,并勾选"Include Sample Pages".

推荐答案

我想通了, .NET 8引入了一个名为Auto的新呈现模式,从而解决了这个问题.只需添加@rendermode Auto指令即可.这实质上意味着,在初始页面加载@rendermode InteractiveServer和每次暂停加载@rendermode InteractiveClient上使用.在初始加载时,服务器服务于该请求,并且在后台下载所需的WASM,并且在每次紧接着的请求时使用高速缓存的Web组件,因此甚至没有建立到服务器的连接.这样做两全其美,唯一的缺点是需要两个项目--一个用于服务器,一个用于客户端.

Csharp相关问答推荐

编写DataAnnotations自定义验证器的多种方法

通过EFCore上传大量数据.

==和Tuple对象的相等<>

如何注销Microsoft帐户?

如何在没有额外副本的情况下将存储在IntPtr下的原始图像数据写入WinUI3中的Image控件?

具有单一导航属性的EF核心一对多关系

异步实体框架核心查询引发InvalidOperation异常

Docker Container中的HttpRequest后地址不可用

取决于您的数据量的多个嵌套循环

C#中Java算法的类似功能

当我没有此令牌时,为什么语法报告EOF错误?

LINQ to Entities中的加权平均值

在implementationFactory中避免循环依赖

岛屿和框架中的自定义控件库.Navigate-AccessViolationException

如何使用.NET Aspire从Blazor应用程序与GRPC API通信?

并发表更新.EF核心交易

根据优先级整理合同列表

try 访问字典中的模拟对象时引发KeyNotFoundException

如何在Cake脚本中设置MSBuild.exe的绝对路径

在Unity C#中按键点击错误的参数