Better Programming

Advice for programmers.

Follow publication

Member-only story

Exploring Web Workers in Angular

Kagklis Vasileios
Better Programming
Published in
6 min readNov 2, 2022
Photo by Johannes Plenio: https://www.pexels.com/photo/selective-focus-photography-of-two-men-builder-figurines-1445324/

This article is about — you guessed it — web workers in Angular.

Web workers allow us to execute JavaScript off the main thread. We will present how they can improve application performance and user experience.

More threads mean more things are done at the same time. But with great power comes great responsibility. We need to manage and synchronize the threads.

Looks like we’ve got a few points to cover.

Let’s get started!

A Few Words Before the Action

Angular is a TypeScript-based framework for building single-page web applications. TypeScript is a superset of JavaScript.

But, as you may already know, browsers can only understand JavaScript. Therefore, everything in an Angular project must be “transpiled” into JavaScript.

JavaScript is a single-threaded language; thus, any application is built with Angular. Everything runs on a single thread, the so-called main thread.

A single thread can do only one thing at any given moment. This can be problematic when running computationally expensive commands.

Imagine that our application needs to perform heavy calculations or render large charts. At some point, the application freezes while the main thread struggles to do all the work.

Bummer! Is there a way to avoid this and improve user experience?

Enter web workers!

The MDN documentation states, “Web workers are a simple means for web content to run scripts in background threads.”

Web workers are separate threads that can run scripts in the background without interfering with the main thread. They can run independently without affecting the performance of the page.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (4)

Write a response