What’s the difference between Shared Worker and Worker in HTML5?
Very basic distinction: a Worker can only be accessed from the script that created it, a SharedWorker can be accessed by any script that comes from the same domain.
Very basic distinction: a Worker can only be accessed from the script that created it, a SharedWorker can be accessed by any script that comes from the same domain.
ES2015 modules in Workers are available in Safari and in Chromium browsers. If other browsers / versions are your target, you still need to use importScripts(). When available, you create a module-worker like this: new Worker(“worker.js”, { type: “module” }); See: https://html.spec.whatwg.org/#module-worker-example These are the bug-reports for each browser: Firefox: Fixed! expected in version 111 … Read more
Web workers only have access to the following: XMLHttpRequest Application Cache Create other web workers navigator object location object setTimeout method clearTimeout method setInterval method clearInterval method Performance object (mark,measure,now methods: caniuse?) IndexedDB API (see: caniuse?) importScripts method JSON Worker The window or parent objects are not accessible from a Web worker therefore you can’t … Read more
Many thanks to Mattias Buelens who pointed me in the right direction. Here’s a working example. The project structure is: dist src generic-tsconfig.json main (typescript files) tsconfig.json dedicated-worker (typescript files) tsconfig.json service-worker (typescript files) tsconfig.json src/generic-tsconfig.json This contains the config common to each project: { “compilerOptions”: { “target”: “esnext”, “module”: “esnext”, “strict”: true, “moduleResolution”: “node”, … Read more
Yes. To quote MDN: The navigator.hardwareConcurrency read-only property returns the number of logical processors available to run threads on the user’s computer… Modern computers have multiple physical processor cores in their CPU (two or four cores is typical), but each physical core is also usually able to run more than one thread at a time … Read more
Communication with Web workers happens through a messaging mechanism. Intercepting these messages happens in a call back. In AngularJS, the best location to put a web worker is in a service as you duly noted. The best way to deal with this is to use promises, which Angular works amazingly with. Here is an example … Read more
The current code (listed below) has been now in use in the Stackoverflow javascript chat room for a while and so far the toughest problem was Array(5000000000).join(“adasdadadasd”) instantly crashing some browser tabs for me when I was running the code executor bot. Monkeypatching Array.prototype.join seems to have fixed this and the maximum execution time of … Read more
As several comments have already pointed out, Workers really are multi-threaded. Some points which may help clarify your thinking: JavaScript is a language, it doesn’t define a threading model, it’s not necessarily single threaded Most browsers have historically been single threaded (though that is changing rapidly: IE, Chrome, Firefox), and most JavaScript implementations occur in … Read more
After a series of tests, I confirmed that this is a Mozilla Firefox issue (it affects all windows desktop versions I tried). With Google Chrome, Opera, or even Firefox mobile, the regexp matches take about the same, worker or not. If you need this issue fixed, be sure to vote on bug report on bugzilla. … Read more
Summary blob: for Chrome 8+, Firefox 6+, Safari 6.0+, Opera 15+ data:application/javascript for Opera 10.60 – 12 eval otherwise (IE 10+) URL.createObjectURL(<Blob blob>) can be used to create a Web worker from a string. The blob can be created using the BlobBuilder API deprecated or the Blob constructor. Demo: http://jsfiddle.net/uqcFM/49/ // URL.createObjectURL window.URL = window.URL … Read more