Sample app contains commented code in dashboard.js. This code blocks the main thread for 10 seconds, if you uncomment it — you will see that app becomes frozen for 10 seconds:
Web Worker is defined in dashboard.js. Web Worker is a separate JS file, which is being used for Worker object. API allows to send and receive messages, this way we can communicate to and from Web Worker (start a new task and receive message when task is completed):
Web Worker code — onmessage invoked when the message arrives from the main thread. postMessage sends message back to the main thread:
The sample app is available on GitHub repo.
Originally published at http://andrejusb.blogspot.com.