feat(index.html): reload when resource fails to load
The page will be reloaded if any of the mandatory scripts/resources fails to load. The reload will be delayed with exponential backoff starting from 2 seconds. The retry attempt counter is passed as 'rCounter' query attribute.
This commit is contained in:
parent
a09b8ce56e
commit
a4dcf5f8df
34
index.html
34
index.html
|
@ -31,6 +31,40 @@
|
|||
document.body.innerHTML
|
||||
= "The application failed to load, missing file: "
|
||||
+ fileRef;
|
||||
|
||||
// The whole complex part below implements page reloads with
|
||||
// "exponential backoff". The retry attempt is passes as
|
||||
// "rCounter" query parameter
|
||||
var href = window.location.href;
|
||||
|
||||
var retryMatch = href.match(/.+(\?|&)rCounter=(\d+)/);
|
||||
var retryCountStr = retryMatch ? retryMatch[2] : "0";
|
||||
var retryCount = Number.parseInt(retryCountStr);
|
||||
|
||||
if (retryMatch == null) {
|
||||
var separator = href.indexOf("?") === -1 ? "?" : "&";
|
||||
var hashIdx = href.indexOf("#");
|
||||
|
||||
if (hashIdx === -1) {
|
||||
href += separator + "rCounter=1";
|
||||
} else {
|
||||
var hashPart = href.substr(hashIdx);
|
||||
|
||||
href = href.substr(0, hashIdx)
|
||||
+ separator + "rCounter=1" + hashPart;
|
||||
}
|
||||
} else {
|
||||
var separator = retryMatch[1];
|
||||
|
||||
href = href.replace(
|
||||
/(\?|&)rCounter=(\d+)/,
|
||||
separator + "rCounter=" + (retryCount + 1));
|
||||
}
|
||||
|
||||
var delay = Math.pow(2, retryCount) * 2000;
|
||||
|
||||
window.setTimeout(
|
||||
function () { window.location.replace(href); }, delay);
|
||||
};
|
||||
window.removeEventListener(
|
||||
'error', loadErrHandler, true /* capture phase */);
|
||||
|
|
Loading…
Reference in New Issue