Mostra notizie nelle discussioni
Avatar
☺
Scritto da
altg
utente che non utiene
il 2014-11-12 12:29:37.0 alle 2014-11-12 12:29:37.0
Trollate totali: 11540
XMLHttpRequest su chromium vs. firefox
Non capisco una cosa, e non trovo nulla di chiaro su internet in proposito. Mi sembra strano che nessuno l'abbia notato, quindi sospetto di star facendo qualcosa di sbagliato io, perche` la differenza sui due browsers e` rilevante. In pratica, ho un problema nel compilatore Lino4: il caricamento di librerie, quando il compilatore trova una "include", viene fatto con una richiesta XMLHttp sincrona (non asincrona) dal worker del compilatore. Ok, e` sincrona e quindi bloccante, pero` ovviamente avviene in un worker e non nel thread principale a cui e` legato il DOM e la UI del browser, sicche` dovrebbe essere funzionalmente accettabile per l'utente che non si vede bloccare il browser mentre compila. Infatti non si blocca nulla, pero` c'e` un delay molto alto fra una richiesta e l'altra, oppure le richieste sono lentissime su chromium (o meglio, su entrambi i suoi derivati Chrome e Opera), mentre Firefox fa richieste praticamente istantanee. Ovviamente il mio problema e` che mentre FF compila in una frazione di secondo i semplici listati su cui lavoro ora, Opera e Chrome ci mettono qualcosa come 3 secondi, dando l'impressione che sia il compilatore stesso ad essere lento quando il 99% del tempo e` speso nelle richieste per caricare le librerie. Allego screenshot del profiler:

Immagine postata dall'utente

Qualche idea sul perche`? sembra quasi che i delay siano introdotti ad arte, quasi tutti intorno ai 300 ms, forse una caratteristica del browser per non sovraccaricare i server ed evitare DoS involontari? (pero` mi parrebbe strano che non la disabilitassero per richieste che puntano a localhost)

Allego anche il codice del requester del compilatore: magari e` li` che sbaglio...

        Requester = function (args) {

                this.url = args && typeof args.url == 'string' ? args.url : 'http://localhost:4048';
                this.requester = new XMLHttpRequest ();
                this.requestInProgress = false;
                this.onload = function () { };
                this.onerror = function () { };

                return this;

        };

        Requester.prototype.get = function (args) { var

                async = args && typeof args.async == 'boolean' ? args.async : true,
                binary = args && typeof args.binary == 'boolean' ? args.binary : false;

                if (this.requester && this.requestInProgress == false) {

                        this.onload = args && typeof args.onload == 'function' ? args.onload : function () { };
                        this.onerror = args && typeof args.onerror == 'function' ? args.onerror : function () { };
                        this.requester.open ('GET', this.url + (args && typeof args.uri == 'string' ? args.uri : empty), async);

                        if (binary)

                                this.requester.overrideMimeType ('text/plain; charset=x-user-defined');

                        if (async) {

                                this.requestInProgress = true;
                                this.requester.onreadystatechange = this.rscHandler.bind (this);
                                this.requester.send ();
                                return null;

                        }

                        this.requester.send ();

                        return this.requester.status == 200 ? {

                                status: this.requester.status,
                                response: this.requester.response,
                                text: this.requester.responseText,
                                xml: this.requester.responseXML

                        } : {

                                status: this.requester.status,
                                response: null,
                                text: empty,
                                xml: null

                        };

                }

        };

        Requester.prototype.rscHandler = function () {

                if (this.requester.readyState == 4) {

                        this.requestInProgress = false;

                        if (this.requester.status == 200) {

                                this.onload ({

                                        status: this.requester.status,
                                        response: this.requester.response,
                                        text: this.requester.responseText,
                                        xml: this.requester.responseXML

                                });

                                return;

                        }

                        this.onerror ({

                                status: this.requester.status,
                                response: null,
                                text: empty,
                                xml: null

                        });

                }

        };


ho tralasciato il metodo "post" perche` tanto il problema affligge soprattutto le richieste GET, che sono di piu`. E` vero che nel codice c'e` un flag "requestInProgress" che protegge un'istanza del requester dall'eseguire piu` di una richiesta per volta, ma c'era piu` per sicurezza che per motivi pratici, tanto poi ogni richiesta crea una nuova istanza con la sua copia del flag.

Non capisco. Keroppi

Pagina generata in 149 millisecondi

Utenti attivi: 10 nell'ultimo minuto, 20 negli ultimi cinque minuti, 51 negli ultimi 15 minuti