Why is Firefox waiting for the javascript function to complete to launch another function?

We are developing a web application using GWT in the interface.

In GWT, we make calls to the server by adding javascript code as follows:

    public native static void call(int requestId, String url, ICall handler) /*-{
   var callback = "callback" + requestId;

   //Create a script element.
   var script = document.createElement("script");
   script.setAttribute("src", url+callback);
   script.setAttribute("type", "text/javascript");
   script.setAttribute("async", "true");

   //Define the callback function on the window object.
   window[callback] = function(response) {
     handler.@com.xxx.yyy.gui.net.ICall::handleResponse(Ljava/lang/String;)(response);
   } 

   //Attach the script element to the document body.
   document.body.appendChild(script);
  }-*/;

Some calls take a minute, and some others take just a couple of seconds. If we make several calls at the same time, they all run in parallel. This means that a call that ends after 2 seconds should not wait for the call to end, which lasts a minute. This is true in Chrome and Safari. However, Firefox waits for the first function to be called to finish executing other functions.

Why is Firefox waiting for the javascript function to complete to launch another function? How to fix it?

thank

+3
4

HTML5 JavaScript -. , .

function supports_web_workers() {
  return !!window.Worker;
}

.

   // thread1
   var myBread = new Worker('bread.js');

   // thread2
   var myButter = new Worker('butter.js');

, , .

+2

, , Firefox ( Firefox , , ). , Firefox .

, ?

0

JavaScript on the Internet is single-threaded if you are not using workflows (around Firefox 3.5). This is how the website is designed to work, and all browsers will do the same.

0
source

Your question is a little wrong because you are not using xhr as you think, but script injection (jsonp). In this case, firefox will download the files in parallel, but execute the file in the order in which the files are sent to the DOM.

0
source

Source: https://habr.com/ru/post/1757043/


All Articles