0

HTML5 WebWorkers look very promising but at the moment they're not supported by IE8. I'm building a business Saas and I have to support this browser for at least another 2 years.

What would happen if I started implementing a web worker thread and ran it on IE8? Would it just run on a single thread or would it just not work at all?

Thanks.

3
  • Did you try it? What happened? Commented May 8, 2012 at 18:26
  • Not tried, it's not at that stage; just looking to see what would happen if I did. Have you tried it? Commented May 8, 2012 at 18:31
  • 1
    Takes 40 seconds to make a demo! Or test one of the demos online. :) Commented May 8, 2012 at 18:46

2 Answers 2

7

You'll get an error, because the API for creating Web Workers simply does not exist in IE.

e.g.

var worker = new Worker('my_task.js'); 

Will throw an error because Worker is undefined.

If you want to do feature detection, you can check first before creating the worker:

if(window.Worker !== undefined){
   var worker = new Worker('my_task.js'); 
}

Of course, whatever task you've delegated to the webworker won't happen on non-supported browsers, which means you'll need to run the logic on the primary (non worker) context.

Since you post message to (and listen for events/messages from) WebWorkers, if you follow the same approach to your worker task you can just run it in your primary context, and make calls to it in the same way as you would if it were a webworker. This will require some additional legwork on your end, but this way you can easily switch to WebWorkers when you detect it is supported in browser.

Sign up to request clarification or add additional context in comments.

4 Comments

ok, thanks for the answer; I'll stay away from web workers until IE8 dies off some more. Thanks.
@frenchie You don't have to stay away from them completely, you just have to solve your problems intelligently. Build the same API for your WebWorker classes as you would be using it as a worker. Make calls to it the same, etc. That way, if you detect browser support you can still use it
Also, WebWorkers are not supported in IE9 either, so if you're going to wait, you're going to have to wait a long time.
Thanks; I'm building an HTML5 application. The javascript code base is about 9,000 lines and I'm only going to create one implementation; at least for a while.
5

There is a project providing a dummy implementation of web workers for IE < 10: http://code.google.com/p/ie-web-worker/ The API is the same as, but the execution is single-threaded.

It works fine but I found one issue regarding this lib. The code of the worker is executed as soon as

var worker = new Worker('myworker.js');

is called. At this moment no

worker.onmessage = function {...}

is set and messages can't be sent from the worker to the main code. So it might be necessary to start your worker code not before a message is sent from the main code to the worker, e.g.

worker.postMessage('start');

1 Comment

If the worker is very process intensive would it stop execution of the page like it does currently. (eg. looping through a 10,000 object array)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.