Skip to content

Commit acf532e

Browse files
committed
Simplified code
1 parent 5920f75 commit acf532e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

BlazorClientLoadingScreen/wwwroot/index.html

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,35 @@
3939
<script>
4040
function StartBlazor() {
4141
let loadedCount = 0;
42-
const resourcesToLoad = [];
42+
let allRessources = 0;
4343
Blazor.start({
4444
// This function gets called by the Blazor pipeline
4545
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;
4949

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++;
5458

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+
});
5868

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+
}
7271
});
7372
}
7473

0 commit comments

Comments
 (0)