How can I use Web Workers in HTML5?

JavascriptFront End ScriptsWeb Development

Web Workers allow for long-running scripts that are not interrupted by scripts that respond to clicks or other user interactions and allows long tasks to be executed without yielding to keep the page responsive.

Web Workers are background scripts and they are relatively heavyweight and are not intended to be used in large numbers. For example, it would be inappropriate to launch one worker for each pixel of a four-megapixel image.

Web Workers initialized with the URL of a JavaScript file, which contains the code the worker will execute. This code sets event listeners and communicates with the script that spawned it from the main page.

Syntax

Following is the syntax −

var worker = new Worker('bigLoop.js');
raja
Published on 06-Apr-2018 10:25:57
Advertisements