H5--Web Worker

Web Worker is a new feature of H5.

JS is single-threaded, so if the user wants to perform some blocking operations in the message queue, such as delay timeout and timer interval, or the scene with a large amount of data and a very long processing process, it is easy for the page to freeze. Phenomenon. To solve this problem, Web Worker was born.

It uses a background sub-thread to start a new thread and will not be affected by the main thread. Use postMessage and onMessage to send and receive messages. And in order to avoid conflicts with the operation of the DOM by the main thread, the webworker cannot operate the DOM.

var worker = new Worker ( "./worker.js" ) ; //Create a thread

Kill the thread itself by close(), or call worker.terminate() in main to terminate the thread.

worker.onerror can receive error messages.

SharedWorker and DedicatedWorker.

For other specific information, see

http://www.mobibrw.com/2015/2532

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324894248&siteId=291194637