When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.
Everyone wants a website or application which work fast and can execute multiple operations simultaneously without affecting the performance of the page. However, sometimes we experience some delay response or degraded performance of page while executing some large operations. So this problem can be solved using the Web Workers.
Following are some key features of the Web Workers:
- Web-workers are the kernel-level thread.
- Web-workers requires more space and CPU time.
- Web-workers enhances the speed of a website.
- Web-worker executes codes on the client side (not server-side).
- Web worker threads communicate with each other using postMessage() callback method
Types of Web Workers:
In HTML5 Web Workers are of two types:
The dedicated worker can be accessed by only one script which has called it. The dedicated worker thread end as its parent thread ends. Dedicated workers are only used by one or single main thread.
It can be shared by multiple scripts and can communicate using the port. Shared workers can be accessed by different windows, iframes or workers.
Note: In this section, we will use dedicated Web Workers.