https://valiantlynx.github.io/web-worker/
This is a simple web application that demonstrates the usage of web workers to perform computationally intensive tasks without blocking the main thread.
- Clicking the "Do Work" button triggers a web worker that performs a time-consuming calculation in the background.
- The result of the calculation is displayed in the output section.
- Clicking the "Do More Work" button updates the "Random" section with the text "Clicked!"
No installation is required for this application. Simply open the index.html
file in a web browser.
- Open the
index.html
file in a web browser. - Click the "Do Work" button to start the computationally intensive task in the web worker.
- The output section will display the result of the calculation once it is completed.
- Click the "Do More Work" button to update the "Random" section with the text "Clicked!".
- HTML
- JavaScript
The application uses a simple CSS file (style.css
) for basic styling. The following styles are applied:
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
margin: 0;
padding: 20px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#random {
font-size: 24px;
margin-top: 20px;
color: brown;
}
#output {
font-size: 32px;
color: aqua;
margin-top: 20px;
}
- When the "Do Work" button is clicked, an event listener triggers the creation of a new web worker (worker.js).
- The web worker performs a time-consuming calculation in the background.
- Once the calculation is completed, the web worker sends the result back to the main thread.
- The result is then displayed in the output section of the page.
- Clicking the "Do More Work" button updates the "Random" section with the text "Clicked!".
Contributions are welcome! If you have any suggestions, improvements, or feature ideas, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
git subtree add --prefix=apps/web-worker https://github.com/valiantlynx/web-worker.git master --squash
git subtree pull --prefix=apps/web-worker https://github.com/valiantlynx/web-worker.git master --squash
git subtree push --prefix=apps/web-worker https://github.com/valiantlynx/web-worker.git master