This project demonstrates how Web Workers can help run heavy computations without blocking the main thread, ensuring a smooth and responsive user interface (UI).
The example compares two approaches to running a heavy computational task (calculating Fibonacci numbers):
-
Main Thread Execution:
- Runs the task directly on the main thread.
- Blocks the UI during the task, making the application unresponsive.
-
Web Worker Execution:
- Runs the task on a separate background thread using a Web Worker.
- Keeps the UI responsive and interactive while the computation happens in parallel.
- Executes Fibonacci calculation directly, causing the browser to freeze until the task completes (You will not interactive with UI)
- For example, calculating Fibonacci for (n = 45).
- Offloads the same Fibonacci calculation to a dedicated background thread.
- The Web Worker communicates with the main thread via
postMessage
to send results back once the task is complete.
- Clone or download this repository:
git clone <repository_url>
cd <repository_folder>
- Run
Run with Live server