Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Firefox waits until a javascript function is finished to start another function?

we are developing a web application using GWT in the front end.

In GWT we make calls to the server by appending javascript code as stated below:

    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) {
     [email protected]::handleResponse(Ljava/lang/String;)(response);
   } 

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

Some calls take a minute to complete and some others just a couple of seconds. If we make multiple calls at the same time all of them are executed in parallel . This means that a call that ends in 2 seconds does not have to wait until a call that lasts a minute finish. This is true in Chrome and Safari. However Firefox waits until the first invoked function finishes to start the other functions.

Why does Firefox waits until a javascript function is finished to start another function? How to fix this?

Thanks

like image 766
Miguel Avatar asked Mar 10 '26 19:03

Miguel


1 Answers

You can use HTML5 with multithreaded JavaScript through web workers. First check if your browser supports this.

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

Then start using multithreading.

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

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

I never tried this myself so correct me if I'm wrong.

like image 55
stevek-pro Avatar answered Mar 13 '26 08:03

stevek-pro