0

I've got a JSONp in Worker. My JSONp content is big enough (about 3MB). For not blocking the UI, I've tried to put the data loading into Worker, to process it there (to minify or something) and return to the main UI thread a lightweight version for further work.

But. Chrome and IE freeze for about 2-3 seconds (in my case) at the moment after they just finished downloading the JSONp. (Even thought that's being done in separate thread).

enter image description here

It freezes even if I put the JSONp loading into a Worker with importScripts (the code below) and even if I do nothing with the data received.

It just feezes the page UI for a few seconds.

Firefox is doing great with all that. So, is there any way I am doing wrong and there is something to handle that issue?

The code is by "standard": Main js:

var myWorker = new Worker('worker-jsonp.js');
myWorker.addEventListener('message', function (e) {
    // freezing aldeady took place in here
    var data = JSON.parse(e.data);
}, false);
myWorker.postMessage({ url: url, params: params });

The worker:

var myCallback = function (data) {
    // the JSONP callback
    // the freezing takes place even if I comment the next line (do nothing)
    self.postMessage(JSON.stringify(data));
};

self.addEventListener('message', function (e) {
    var url = e.data.url;
    importScripts(url);
}, false);

Thanks!

Agat
  • 4,577
  • 2
  • 34
  • 62
  • http://stackoverflow.com/questions/27514404/web-worker-blocked-by-main-thread-in-chrome?rq=1 may have some insights that are relevant to your problem – Jason Sep 18 '15 at 09:57
  • Thanks for the link, but that's not really what I am talking about. The link talks about a web-worker locked (can not initiate remote requests) when main UI is busy. But in my case it's vise versa: the main thread becomes blocked after importScripts finished downloading of remote script. – Agat Sep 18 '15 at 10:06

0 Answers0