Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    opencart-hyperlocal-marketplace-guide

    Web Worker

    Web Worker is a javascript script execute in the background of web pages without interfering with the user interface, also have been executed from the same HTML page.

    Why Use Web Worker(Benefit of Web worker)–

    Suppose you use the number of concurrency request using UI so after few second you see UI stops working or other words due to concurrency of request UI is not work until all request executed so avoid this issue we use the Web Workers is work without affecting the user interface.

    Type of Web Worker —

    Web Worker is Two type, Shared, and Dedicated Web worker.

    Shared Web Worker —

    Shared Web Worker each web Web Worker can have multiple connections that means you can use multiple pages of single Web Workers. Shared Web Worker constructor creates a new SharedWorker() object instance for representing


    Dedicated Web worker —

    Dedicated Web Worker creating with URL to the javascript file. The Worker() constructor is invoked with the URL to that file as its only argument, a worker is then created and returned.


    Limitations of Web Worker–

    • Web workers cannot access DOM elements.
    • Web workers cannot access global variables and JavaScript functions from the web page.
    • Web workers can’t call alert() or confirm() functions.
    • Window object cannot access inside the web worker.
    • Document object can’t be accessed inside the Web Worker.
    • Parent object can’t be accessed inside the Web Worker.
    • Cross-browser policy.

    Example: In the example, we see how to send and receive data, we use two file first HTML file, and the second js file name is main.js.


    Now main.js file here we see the simple program for check given number is even or odd.


    Output:

    The Web worker sets the property onmessage to a function which will receive messages sent when the worker object’s postMessage().

    In case you have any Query then feel free to ask in the comment section below.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close