Blazor Assembly requires a minimum download of 1.9M. ( New Blazor Web Assembly Project Download Measurement Test, for reference only. )
As programs become more complex and reference more and more, more downloads are needed.
Some websites may have poor networks and it may take some time to load these files.
For some websites, it doesn't expose wasm pages to visitors from the start.
wasm is better suited for App programs that require a lot of interaction with the server.
For example, website background management interface, chat background interface, etc.
So, in most cases, visitors go to the website first, then log in, and then to wasm.
In this case, an example of how to pre-load the dll required by wasm is provided
To achieve this effect:
Visitors to the website Welcome page=> Welcome page Preload dll resources behind => Visitors to the WASM interface, load faster.
First, this example uses theAsp.NetHosted, plus PWA mode.
So there isAsp.NetCore's program is running on the server.
Modify WASM home page address
Put Index.razor Change the address to / Home because we need the first page of the website to be the welcome page.
New Web Site Home Page
We useAsp.NetCore's razor page serves as the home page. Without a Controller, you can use MVC, or even Blazor Server Side, in your own way.
Modify Home Page Code
This is a welcome page. The welcome page is very simple, downloads very quickly, and users will be able to open it soon.
(A simple progress bar has been added. This page can be designed as a Loading interface)
Since this is a test page in development and the dll is not clipped, the download will be 6.6M. After publishing the program, the download will be significantly reduced: ( New Blazor Web Assembly Project Download Measurement Test, for reference only. )
According to the script of the page, after the welcome page is displayed, all the files required by wasm will be downloaded in advance.
After clicking into the system,
You can see that most of the files have been cached successfully. Subsequent downloads are only 61KB. The main downloads are bootstrap css and iconic fonts.
Analyzing scripting principles:
The key to this is _framework/blazor.boot.json,.
When we read this file on the client side, we know where the resources we need are.
These files can be processed by looping.assembly and.runtime
It's still quite simple.
Here's how it works. You can optimize your processing to suit your business needs.