Web and Service Workers

Let's suppose that you are building a cool web app, say, to factorize a number to two prime numbers. Now, this involves a lot of CPU-intensive work, which will block the main UI thread. The main UI thread is the traffic lane that the end user directly observes and perceives. If it seems congested (laggy) or blocked, even for a few seconds, it destroys the user experience.

This is where web workers come into the picture. Web workers can be thought of as those side-lanes available on the road where you can divert heavy and slow (CPU-intensive) trucks so that you don't block a user's shining Lamborghini on the main road (the main UI thread).

On the other hand, service workers are quite cool, too. A service worker is your ...

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.