Add retry for assets
This commit is contained in:
parent
00ccbf5db9
commit
2309172bfc
14
shell.html
14
shell.html
|
@ -230,9 +230,15 @@
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
const pdiv = document.getElementById("progress");
|
const pdiv = document.getElementById("progress");
|
||||||
let showTimer = 0;
|
let showTimer = 0;
|
||||||
|
let abortTimer = 0;
|
||||||
|
|
||||||
|
const retry = () => {
|
||||||
|
xhr.abort();
|
||||||
|
getLazyAsset(url, filename, callback);
|
||||||
|
}
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 400) {
|
||||||
pdiv.innerHTML = `${filename} - done`;
|
pdiv.innerHTML = `${filename} - done`;
|
||||||
hideTimer = setTimeout(() => {
|
hideTimer = setTimeout(() => {
|
||||||
pdiv.style.opacity = '0';
|
pdiv.style.opacity = '0';
|
||||||
|
@ -241,12 +247,16 @@
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
clearTimeout(showTimer);
|
clearTimeout(showTimer);
|
||||||
|
clearTimeout(abortTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.onprogress = function (event) {
|
xhr.onprogress = function (event) {
|
||||||
const loaded = Math.round(event.loaded / 1024);
|
const loaded = Math.round(event.loaded / 1024);
|
||||||
const total = Math.round(event.total / 1024);
|
const total = Math.round(event.total / 1024);
|
||||||
pdiv.innerHTML = `${filename} - ${loaded}KB / ${total}KB`;
|
pdiv.innerHTML = `${filename} - ${loaded}KB / ${total}KB`;
|
||||||
|
|
||||||
|
clearTimeout(abortTimer);
|
||||||
|
abortTimer = setTimeout(retry, 3000);
|
||||||
};
|
};
|
||||||
xhr.open('GET', url);
|
xhr.open('GET', url);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
@ -257,6 +267,8 @@
|
||||||
pdiv.style.opacity = '0.5';
|
pdiv.style.opacity = '0.5';
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
abortTimer = setTimeout(retry, 3000);
|
||||||
|
|
||||||
if (hideTimer) {
|
if (hideTimer) {
|
||||||
clearTimeout(hideTimer);
|
clearTimeout(hideTimer);
|
||||||
hideTimer = 0;
|
hideTimer = 0;
|
||||||
|
|
Loading…
Reference in New Issue