Web Workers:
It provides a fully isolated computing method for background computing.
Inaccessible DOM APIs
Inaccessible window object
Inaccessible document object
Strong isolation ensures that parallel computing results are correct (lockless mechanism)
Start worker
1. Define the Worker object var w = new Worker ("calc. js ");
Communication:
The message event is used to communicate with the caller.
AddEventListener ('message', function (evt ){});
PostMessage () is used to send messages to Worker.
W. postMessage (imgData );
The data is formatted as json.
Each sending is a copy of the source object. The object is large and the performance is significantly reduced.
Worker access interface:
SetTimeout ()/clearTimeout ();
SetInterval ()/clearInterval ()
ImportScript () introduces other js files
Read url
Xmlhttprequest can be sent
Shared worker Shared data
Author: shiyuan17