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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access