|
39 | 39 | <script>
|
40 | 40 | function StartBlazor() {
|
41 | 41 | let loadedCount = 0;
|
42 |
| - const resourcesToLoad = []; |
| 42 | + let allRessources = 0; |
43 | 43 | Blazor.start({
|
44 | 44 | // This function gets called by the Blazor pipeline
|
45 | 45 | loadBootResource:
|
46 |
| - function (type, filename, defaultUri, integrity) { |
47 |
| - if (type === "dotnetjs") |
48 |
| - return defaultUri; |
| 46 | + function (type, filename, defaultUri, integrity) { |
| 47 | + if (type === "dotnetjs") |
| 48 | + return defaultUri; |
49 | 49 |
|
50 |
| - const fetchResources = fetch(defaultUri, { |
51 |
| - cache: 'no-cache', |
52 |
| - integrity: integrity |
53 |
| - }); |
| 50 | + // As "fetchResources" is a promise we don't block |
| 51 | + const fetchResources = fetch(defaultUri, { |
| 52 | + cache: 'no-cache', |
| 53 | + integrity: integrity |
| 54 | + }); |
| 55 | + |
| 56 | + // Add one to the total amount of stuff we have to fetch |
| 57 | + allRessources++; |
54 | 58 |
|
55 |
| - // We "collect" all resources to know how many there are |
56 |
| - // As "fetchResources" is a promise this will be done asynchronously |
57 |
| - resourcesToLoad.push(fetchResources); |
| 59 | + // That promise is fulfilled once one resource is done fetching |
| 60 | + // When this happens we update the progress bar |
| 61 | + fetchResources.then((_) => { |
| 62 | + // When fetching is done, indicate this in our loading bar |
| 63 | + loadedCount++; |
| 64 | + const percentLoaded = 100 * loadedCount / allRessources; |
| 65 | + const progressbar = document.getElementById('progressbar'); |
| 66 | + progressbar.style.width = percentLoaded + '%'; |
| 67 | + }); |
58 | 68 |
|
59 |
| - // That promise is fulfilled once one resource is done fetching |
60 |
| - // When this happens we |
61 |
| - fetchResources.then((_) => { |
62 |
| - // When fetching is done, indicate this in our loading bar |
63 |
| - loadedCount++; |
64 |
| - const totalCount = resourcesToLoad.length; |
65 |
| - const percentLoaded = 100 * loadedCount / totalCount; |
66 |
| - const progressbar = document.getElementById('progressbar'); |
67 |
| - progressbar.style.width = percentLoaded + '%'; |
68 |
| - }); |
69 |
| - |
70 |
| - return fetchResources; |
71 |
| - } |
| 69 | + return fetchResources; |
| 70 | + } |
72 | 71 | });
|
73 | 72 | }
|
74 | 73 |
|
|
0 commit comments