From the course: Vanilla JavaScript: Web Performance Optimization APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detect long tasks

Detect long tasks - JavaScript Tutorial

From the course: Vanilla JavaScript: Web Performance Optimization APIs

Start my 1-month free trial

Detect long tasks

- [Narrator] A recent addition to the performance family is the Long Task API. The long task API will let us detect when we have some code that is taking the thread for too much time, so it's a long task. And we should do something different, such as using a web worker, or changing the algorithm. That's not available in every browser today. In fact it's fairly experimental. So we need to do something similar to paint timing. This is the long task API, we also need an observer in this case, it's mandatory to have an observer. We going to create the long task observer. It's a new performance observer that we receive a list and we're going to first try to observe on that observer and in this case, the entry type is Longtask, one word. We need the catch, and we're going to observe here for now. We will just get the entries, all of them and for each entry, we're going to execute the very simple code that we'll call Perf, and we'll say Longtask and for the name, we're going to specify…

Contents