A web worker is a JavaScript running in the background, without affecting the performance of the page. When executing scripts in an HTML page, the page becomes unresponsive until the script is finished. A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background. Everyone wants a website or application which work fast and can execute multiple operations simultaneously without affecting the performance of the page. However, sometimes we experience some delay response or degraded performance of page while executing some large operations. So this problem can be solved using the Web Workers. Web Workers are the multithreaded object which can execute multiple JavaScript in parallel without affecting the performance of the application or webpage. Following are some key features of the Web Workers:
Tips: Before working with HTML Web Workers you must have knowledge of JavaScript as the Web Worker depends on JavaScript.
Types of Web Workers:In HTML5 Web Workers are of two types:
The dedicated worker can be accessed by only one script which has called it. The dedicated worker thread end as its parent thread ends. Dedicated workers are only used by one or single main thread.
It can be shared by multiple scripts and can communicate using the port. Shared workers can be accessed by different windows, iframes or workers. Note: In this section, we will use dedicated Web Workers. |
<!DOCTYPE html>
<html>
<head>
<title>Web Worker API</title>
</head>
<body>
<h2>Example to check the browser support of Web Workers</h2>
<div id="supported"></div>
<div id="unsupported"></div>
<button onclick="worker();">click me</button>
<script type="text/javascript">
function worker()
{
if(typeof(Worker)!=="undefined"){
document.getElementById("supported").innerHTML="Supporting the browser";
}
else
{
document.getElementById("unsupported").innerHTML="Not supporting";}
}
</script>
</body>
</html>
Reffered: https://www.javatpoint.com/html-web-workers
What is HTML Web Workers API | HTML Web Workers API |
What types of browsers will support | HTML Web Workers API |
How to work a HTML Web Workers | HTML Web Workers API |
How to check Web Worker Support | HTML Web Workers API |
How to create HTML Web Worker File | HTML Web Workers API |
How to Create a Web Worker Object | HTML Web Workers API |
How to Terminate a Web Worker | HTML Web Workers API |
How to Reuse the Web Worker | HTML Web Workers API |
Full Web Worker Example Code | HTML Web Workers API |
What is Web Workers and the DOM | HTML Web Workers API |
Example of HTML Web Worker | HTML Web Workers API |
Read Full: | HTML Web Workers API |
Category: | Web Tutorial |
Sub Category: | HTML Web Workers API |
Uploaded: | 10 months ago |
Uploaded by: | Admin |
Views: | 54 |