---
source: https://iinventedlight.com/library/notes/javascript-long-tasks.md
title: "Long tasks: work on the main thread that lasts over 50 ms"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (web.dev); CC-BY-4.0 (WHATWG); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: web.dev, Optimize long tasks; WHATWG, HTML Living Standard, Web application APIs. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright WHATWG contributors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: javascript-long-tasks"
tags: [javascript, performance, main-thread, event-loop, web]
client: Librarian
sources:
  - id: S1
    title: "Optimize long tasks"
    publisher: web.dev
    url: https://web.dev/articles/optimize-long-tasks
    accessed: 2026-11-23
    license: "CC-BY-4.0"
  - id: S2
    title: "HTML Living Standard, Web application APIs"
    publisher: WHATWG
    url: https://html.spec.whatwg.org/multipage/webappapis.html
    accessed: 2026-11-23
    license: "CC-BY-4.0"
---
# Long tasks: work on the main thread that lasts over 50 ms
**Answer:** A task is any discrete piece of work that the browser does. The main thread can only process one task at a time. Work lasting over 50 milliseconds is a long task. HTML gives each agent an event loop with task queues.

## What counts as a task

web.dev treats a task as a discrete unit of browser work: rendering, parsing HTML and CSS, running JavaScript, and other work you may not control.

## The main thread and long tasks

Most of this work, and almost all JavaScript you write, runs on the main thread.

Only one task is processed on the main thread at a time.

A task lasting longer than 50 milliseconds is called a long task.

## How HTML models the event loop

User agents use event loops to coordinate events, scripts, rendering, and networking.

Each agent has an associated event loop, unique to that agent.

An event loop has one or more task queues, and a task queue is a set of tasks.

The microtask queue is not a task queue.

## See also

- [javascript-fetch](https://iinventedlight.com/library/notes/javascript-fetch/)
- [javascript-modules](https://iinventedlight.com/library/notes/javascript-modules/)
- [webdev-inp](https://iinventedlight.com/library/notes/webdev-inp/)

## Claims

- id: C1
  claim: A task is any discrete piece of work the browser does.
  source: S1
  evidence: "A task is any discrete piece of work that the browser does"

- id: C2
  claim: The main thread can process only one task at a time.
  source: S1
  evidence: "The main thread can only process one task at a time"

- id: C3
  claim: A task longer than 50 milliseconds is a long task.
  source: S1
  evidence: "Any task that takes longer than 50 milliseconds is a long task"

- id: C4
  claim: Each agent has its own event loop.
  source: S2
  evidence: "Each agent has an associated event loop"

- id: C5
  claim: An event loop has one or more task queues.
  source: S2
  evidence: "An event loop has one or more task queues"

- id: C6
  claim: The microtask queue is not a task queue.
  source: S2
  evidence: "The microtask queue is not a task queue"

## Sources

- [S1] Optimize long tasks. web.dev. https://web.dev/articles/optimize-long-tasks . License: CC-BY-4.0. Accessed 2026-11-23.

- [S2] HTML Living Standard, Web application APIs. WHATWG. https://html.spec.whatwg.org/multipage/webappapis.html . License: CC-BY-4.0. Accessed 2026-11-23.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Optimize long tasks; WHATWG, HTML Living Standard, Web application APIs. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. CC-BY-4.0 (https://raw.githubusercontent.com/whatwg/html/main/LICENSE). Copyright WHATWG contributors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
