Async Api Calls Inside JavaScript Web workers

|
| By Harleen Kaur

Web workers is a JavaScript technology for browsers to support running of the script independently in a separate thread from the main thread. It is like a background process without affecting the screen.
To apply this, you will need to create a worker file and create an instance of the worker file in the main script file. Let’s say ‘app-worker.js’ is the worker JS file and ‘main.js’ is a script file referred to in the HTML page(view page in our application). We can perform operations through the worker file by sending messages to the worker file using postMessage in the format (json, string..) such as