Web Workers: Parallel Tasks and Message Passing
📰 Medium · JavaScript
Learn to use Web Workers for parallel tasks and message passing to keep your UI responsive, even with heavy computations
Action Steps
- Create an HTML file to serve as the entry point for your web application
- Create a JavaScript file for the main thread and another for the Web Worker
- Use the Web Worker API to create a new worker and post messages to it
- Handle messages in the Web Worker and post responses back to the main thread
- Use the Web Worker to perform heavy computations without blocking the main thread
Who Needs to Know This
Frontend developers and engineers can benefit from using Web Workers to improve the performance and responsiveness of their web applications, especially when dealing with resource-intensive tasks
Key Insight
💡 Web Workers allow you to run scripts in background threads, enabling parallel execution and keeping the UI running smoothly
Share This
💡 Use Web Workers to run heavy tasks in the background and keep your UI responsive! #webworkers #javascript
Key Takeaways
Learn to use Web Workers for parallel tasks and message passing to keep your UI responsive, even with heavy computations
Full Article
Title: Web Workers: Parallel Tasks and Message Passing
URL Source: https://medium.com/@ockert8080/web-workers-parallel-tasks-and-message-passing-cc9c5aab479e?source=rss------javascript-5
Published Time: 2026-04-22T19:47:19Z
Markdown Content:
# Web Workers: Parallel Tasks and Message Passing | by Ockert van Schalkwyk | Apr, 2026 | Medium
[Sitemap](https://medium.com/sitemap/sitemap.xml)
[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)
[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)
Get app
[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)
[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Web Workers: Parallel Tasks and Message Passing
[](https://medium.com/@ockert8080?source=post_page---byline--cc9c5aab479e---------------------------------------)
[Ockert van Schalkwyk](https://medium.com/@ockert8080?source=post_page---byline--cc9c5aab479e---------------------------------------)
Follow
4 min read
·
Just now
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Fcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&user=Ockert+van+Schalkwyk&userId=464dac86783e&source=---header_actions--cc9c5aab479e---------------------clap_footer------------------)
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2Fcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=---header_actions--cc9c5aab479e---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=---header_actions--cc9c5aab479e---------------------post_audio_button------------------)
Share
Press enter or click to view image in full size

## Introduction
Here we look at executing heavy tasks on the main thread versus using Web Workers.
## Overview
When a heavy computation runs on the main thread in the browser, it blocks the browser, making the UI unresponsive. Web Workers allow you to run scripts in background threads, enabling parallel execution and keeping the UI running smoothly.
## Steps
Create `index.html`
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<pre id="output"></pre>
<script src="js/main.js"></script>
<script src="js/task.js"></script>
</body>
</html>
Create `./js/task.js`
// This function blocks the thread it runs on for
URL Source: https://medium.com/@ockert8080/web-workers-parallel-tasks-and-message-passing-cc9c5aab479e?source=rss------javascript-5
Published Time: 2026-04-22T19:47:19Z
Markdown Content:
# Web Workers: Parallel Tasks and Message Passing | by Ockert van Schalkwyk | Apr, 2026 | Medium
[Sitemap](https://medium.com/sitemap/sitemap.xml)
[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)
[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)
Get app
[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)
[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)
Sign up
[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

# Web Workers: Parallel Tasks and Message Passing
[](https://medium.com/@ockert8080?source=post_page---byline--cc9c5aab479e---------------------------------------)
[Ockert van Schalkwyk](https://medium.com/@ockert8080?source=post_page---byline--cc9c5aab479e---------------------------------------)
Follow
4 min read
·
Just now
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Fcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&user=Ockert+van+Schalkwyk&userId=464dac86783e&source=---header_actions--cc9c5aab479e---------------------clap_footer------------------)
[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2Fcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=---header_actions--cc9c5aab479e---------------------bookmark_footer------------------)
[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Dcc9c5aab479e&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40ockert8080%2Fweb-workers-parallel-tasks-and-message-passing-cc9c5aab479e&source=---header_actions--cc9c5aab479e---------------------post_audio_button------------------)
Share
Press enter or click to view image in full size

## Introduction
Here we look at executing heavy tasks on the main thread versus using Web Workers.
## Overview
When a heavy computation runs on the main thread in the browser, it blocks the browser, making the UI unresponsive. Web Workers allow you to run scripts in background threads, enabling parallel execution and keeping the UI running smoothly.
## Steps
Create `index.html`
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<pre id="output"></pre>
<script src="js/main.js"></script>
<script src="js/task.js"></script>
</body>
</html>
Create `./js/task.js`
// This function blocks the thread it runs on for
DeepCamp AI