Checking if worker support is available

Although web workers have been around for quite a long time and support is very strong, you still might want to check if web worker support is available in a client's browser (for example, Opera Mini doesn't support it). If it isn't, then just load the web worker file in the main script as well, and let your user feel the heat.

Web workers are available as a window object, so that is pretty much all you have to check in order to get started:

if(typeof window.Worker !== "function") {    // worker not available} else {    // good to go}

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.