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.
This commit is contained in:
parent
e349cc59ad
commit
0354dd2c24
31
index.html
31
index.html
|
@ -6,6 +6,37 @@
|
|||
<script>
|
||||
window.indexLoadedTime = window.performance.now();
|
||||
console.log("(TIME) index.html loaded:\t", indexLoadedTime);
|
||||
// XXX the code below listeners for errors and displays an error message
|
||||
// in the document body when any of the required files fails to load.
|
||||
// The intention is to prevent from displaying broken page.
|
||||
var criticalFiles = [
|
||||
"config.js",
|
||||
"utils.js",
|
||||
"do_external_connect.js",
|
||||
"interface_config.js",
|
||||
"lib-jitsi-meet.min.js",
|
||||
"app.bundle.min.js",
|
||||
"all.css"
|
||||
];
|
||||
var loadErrHandler = function(e) {
|
||||
var target = e.target;
|
||||
// Error on <script> and <link>(CSS)
|
||||
// <script> will have .src and <link> .href
|
||||
var fileRef = (target.src ? target.src : target.href);
|
||||
if (("SCRIPT" === target.tagName || "LINK" === target.tagName)
|
||||
&& criticalFiles.some(
|
||||
function(file) { return fileRef.indexOf(file) !== -1 })) {
|
||||
window.onload = function() {
|
||||
document.body.innerHTML
|
||||
= "The application failed to load, missing file: "
|
||||
+ fileRef;
|
||||
};
|
||||
window.removeEventListener(
|
||||
'error', loadErrHandler, true /* capture phase */);
|
||||
}
|
||||
}
|
||||
window.addEventListener(
|
||||
'error', loadErrHandler, true /* capture phase type of listener */);
|
||||
</script>
|
||||
<script><!--#include virtual="/config.js" --></script><!-- adapt to your needs, i.e. set hosts and bosh path -->
|
||||
<script src="utils.js?v=1"></script>
|
||||
|
|
Loading…
Reference in New Issue