Search code examples
javascriptextjssencha-cmd

Is there a better way to add onerror callback on app.js script tag if it fails to load?


sometimes app.js is not loaded due to 500 server error and it shows blank page, but it will be better to display message that app is not available now. So I found a way to inject into bin\Sencha\Cmd\6.5.3.6\ant\build\app\Boot.js#loadElement function and fix onerror callback for script tag in such way:

loadElement: function() {
    var me = this,
        complete = function(){
            // me.el.onerror = me.el.onload = emptyFn;
            me.el.onload = emptyFn;
            if (me.el.src && me.el.src.includes('app.js?')) {
                alert('error loading app.js');
            }
            me.el = null;
            me.loaded = me.evaluated = me.done = true;
            me.notifyRequests();
        };
    me.createLoadElement(function(){
        complete();
    });
    me.evaluateLoadElement();
    return true;
},

Is there a better way to add onerror callback on app.js script tag if app.js fails to load?


Solution

  • Very strange error for static file.

    I did not find a better solution at frontend. But your decision must be used carefully. If you try to build on the server, this code will also have to be modified again.

    Best way, on me opinion, is fix problem with 500 on server. Find out why 500 occurs on the server, and when you catch an exception and instead of connecting an app.js rendering script tag with alert