Kaynağa Gözat

feat(index.html): prevent from displaying broken page

The commit adds an error listener which will replace the document body
with an error message if any of the files required for the app to
be displayed correctly fails to load.
master
paweldomas 8 yıl önce
ebeveyn
işleme
0354dd2c24
1 değiştirilmiş dosya ile 31 ekleme ve 0 silme
  1. 31
    0
      index.html

+ 31
- 0
index.html Dosyayı Görüntüle

@@ -6,6 +6,37 @@
6 6
     <script>
7 7
         window.indexLoadedTime = window.performance.now();
8 8
         console.log("(TIME) index.html loaded:\t", indexLoadedTime);
9
+        // XXX the code below listeners for errors and displays an error message
10
+        // in the document body when any of the required files fails to load.
11
+        // The intention is to prevent from displaying broken page.
12
+        var criticalFiles = [
13
+            "config.js",
14
+            "utils.js",
15
+            "do_external_connect.js",
16
+            "interface_config.js",
17
+            "lib-jitsi-meet.min.js",
18
+            "app.bundle.min.js",
19
+            "all.css"
20
+        ];
21
+        var loadErrHandler = function(e) {
22
+            var target = e.target;
23
+            // Error on <script> and <link>(CSS)
24
+            // <script> will have .src and <link> .href
25
+            var fileRef = (target.src ? target.src : target.href);
26
+            if (("SCRIPT" === target.tagName || "LINK" === target.tagName)
27
+                && criticalFiles.some(
28
+                    function(file) { return fileRef.indexOf(file) !== -1 })) {
29
+                window.onload = function() {
30
+                    document.body.innerHTML
31
+                        = "The application failed to load, missing file: "
32
+                            + fileRef;
33
+                };
34
+                window.removeEventListener(
35
+                    'error', loadErrHandler, true /* capture phase */);
36
+            }
37
+        }
38
+        window.addEventListener(
39
+            'error', loadErrHandler, true /* capture phase type of listener */);
9 40
     </script>
10 41
     <script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
11 42
     <script src="utils.js?v=1"></script>

Loading…
İptal
Kaydet