Horje
What is HTML Web Workers API | HTML Web Workers API Code
What is HTML Web Workers API

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:

  • Web-workers are threaded JavaScript.
  • Web-workers are the kernel-level thread.
  • Web-workers requires more space and CPU time.
  • Web-workers enhances the speed of a website.
  • Web-worker executes codes on the client side (not server-side).
  • Web worker threads communicate with each other using postMessage() callback method

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:

  • Dedicated Web Workers:

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.

  • Shared Web Workers:

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.


Example of HTML Web Worker

    <!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>  

Output should be:

Example of HTML Web Worker
Reffered: https://www.javatpoint.com/html-web-workers



Read Full::
HTML Web Workers API Code
Category:
HTML Code
Sub Category:
HTML Web Workers API Code
Uploaded:
1 month ago
Uploaded by:
Admin
Views:
1

Related Articles
What is HTML Web Workers API HTML Web Workers API Code
What types of browsers will support HTML Web Workers API Code
How to work a HTML Web Workers HTML Web Workers API Code
How to check Web Worker Support HTML Web Workers API Code
How to create HTML Web Worker File HTML Web Workers API Code
How to Create a Web Worker Object HTML Web Workers API Code
How to Terminate a Web Worker HTML Web Workers API Code
How to Reuse the Web Worker HTML Web Workers API Code
Full Web Worker Example Code HTML Web Workers API Code
What is Web Workers and the DOM HTML Web Workers API Code

Single Articles
Example of HTML Web Worker

Share on: