Sfoglia il codice sorgente

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.
master
paweldomas 8 anni fa
parent
commit
a4dcf5f8df
1 ha cambiato i file con 35 aggiunte e 1 eliminazioni
  1. 35
    1
      index.html

+ 35
- 1
index.html Vedi File

@@ -30,7 +30,41 @@
30 30
                 window.onload = function() {
31 31
                     document.body.innerHTML
32 32
                         = "The application failed to load, missing file: "
33
-                            + fileRef;
33
+                        + fileRef;
34
+
35
+                    // The whole complex part below implements page reloads with
36
+                    // "exponential backoff". The retry attempt is passes as
37
+                    // "rCounter" query parameter
38
+                    var href = window.location.href;
39
+
40
+                    var retryMatch = href.match(/.+(\?|&)rCounter=(\d+)/);
41
+                    var retryCountStr = retryMatch ? retryMatch[2] : "0";
42
+                    var retryCount = Number.parseInt(retryCountStr);
43
+
44
+                    if (retryMatch == null) {
45
+                        var separator = href.indexOf("?") === -1 ? "?" : "&";
46
+                        var hashIdx = href.indexOf("#");
47
+
48
+                        if (hashIdx === -1) {
49
+                            href += separator + "rCounter=1";
50
+                        } else {
51
+                            var hashPart = href.substr(hashIdx);
52
+
53
+                            href = href.substr(0, hashIdx)
54
+                                + separator + "rCounter=1" + hashPart;
55
+                        }
56
+                    } else {
57
+                        var separator = retryMatch[1];
58
+
59
+                        href = href.replace(
60
+                            /(\?|&)rCounter=(\d+)/,
61
+                            separator + "rCounter=" + (retryCount + 1));
62
+                    }
63
+
64
+                    var delay = Math.pow(2, retryCount) * 2000;
65
+
66
+                    window.setTimeout(
67
+                        function () { window.location.replace(href); }, delay);
34 68
                 };
35 69
                 window.removeEventListener(
36 70
                     'error', loadErrHandler, true /* capture phase */);

Loading…
Annulla
Salva