Skip to content

Commit f35f28b

Browse files
committed
Tweaking loading progress
1 parent 83be95e commit f35f28b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

live/demos/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
left: 0;
2626
width: 100vw;
2727
height: 100vh;
28-
//background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
2928
background: linear-gradient(135deg, #0a0a0a 0%, #202020 100%);
3029
display: flex;
3130
flex-direction: column;
@@ -114,6 +113,7 @@
114113
const progressBar = document.getElementById('progress-bar');
115114
const progressText = document.getElementById('progress-text');
116115
const loadingScreen = document.getElementById('loading-screen');
116+
let progs = {}
117117

118118
function updateProgress(progress, text) {
119119
progressBar.style.width = (progress * 100) + '%';
@@ -125,7 +125,7 @@
125125
setTimeout(() => { loadingScreen.style.display = 'none'; }, 500);
126126
}
127127

128-
async function fetchBlock(url, text, startProgress, stepProgress) {
128+
async function fetchBlock(url, text) {
129129
let response = await fetch(url);
130130
const reader = response.body.getReader();
131131
const contentLength = +response.headers.get('Content-Length');
@@ -136,17 +136,18 @@
136136
break;
137137
}
138138
receivedLength += value.length;
139-
const progress = startProgress + (receivedLength / contentLength) * stepProgress;
140-
updateProgress(progress, text)
139+
progs[url] = receivedLength / contentLength;
140+
const minimalProgress = Math.min(...Object.values(progs))
141+
updateProgress(minimalProgress, text)
141142
}
142143
}
143144

144145
updateProgress(0, 'Loading kool...');
145146

146147
// Fetch essential files tracking progress before actually loading them - will be loaded from cache afterwards
147-
await fetchBlock('kool-demo.js', 'Loading kool...', 0, 0.4)
148-
await fetchBlock('assets/fonts/fira-sans-regular.png', 'Loading fonts...', 0.4, 0.6)
149-
await fetchBlock('4ab48fc16bcbc6611bb2.wasm', 'Loading PhysX...', 0.6, 1.0)
148+
fetchBlock('kool-demo.js', 'Loading kool...')
149+
fetchBlock('assets/fonts/fira-sans-regular.png', 'Loading kool...')
150+
fetchBlock('4ab48fc16bcbc6611bb2.wasm', 'Loading kool...')
150151

151152
const script = document.createElement('script');
152153
script.src = 'kool-demo.js';

0 commit comments

Comments
 (0)