web-worker

Using Webworkers in angular app (service worker cache access of data in angular-cli)

泄露秘密 提交于 2019-11-30 03:14:03
问题 I wish to run an function (in the background) using a worker. The data comes from a http request. I am using a mock calculation (e.data[0] * e.data[1] * xhrData.arr[3]) (replaced by a function returning the actual algo result) as below: var ajax = function() { var prom = new Promise(function(resolve, reject){ if (!!XMLHttpRequest) { var xhttp = new XMLHttpRequest(); xhttp.onload = function () { if (this.readyState == 4 && this.status == 200) { resolve(JSON.parse(this.responseText)); } }; //

Use ServiceWorker cache only when offline

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 23:49:41
I'm trying to integrate service workers into my app, but I've found the service worker tries to retrieve cached content even when online, but I want it to prefer the network in these situations. How can I do this? Below is the code I have now, but I don't believe it is working. SW Install code is omitted for brevity. var CACHE_NAME = 'my-cache-v1'; var urlsToCache = [ /* my cached file list */ ]; self.addEventListener('install', function(event) { // Perform install steps event.waitUntil( caches.open(CACHE_NAME) .then(function(cache) { console.log('Opened cache'); return cache.addAll

Cross-Origin Resource Sharing (CORS) using JSONP and Web Workers

安稳与你 提交于 2019-11-29 16:29:11
I am looking for solution how to get/send the data from/to another domain using JSONP in the Web Workers. Since the Web Workers have not access to the DOM it is not possible to append the <script> tag with the url and callback parameter to the <head> tag from Web Workers. Does anybody know, how to get/post the data from/to another domain using JSONP and Web Workers? Thanks, CORS is a specification which has nothing to do with JSONP beyond making it obsolete in newer browsers. It enables cross-domain requests using ordinary XMLHttpRequest calls. Here's an overview of how it works and how to use

Can/should HTML5 Web Workers use CORS for cross-origin?

白昼怎懂夜的黑 提交于 2019-11-29 14:01:04
问题 I ran into an interesting problem while creating a hosted API that relies on web workers. I was hoping to get a little community feedback on it. My server is set up with the appropriate CORS headers to deliver the worker JS files and can be retrieved with an XMLHttpRequest object. However, when the URL is given to new Worker() it fails to build, citing the origin being the problem. This seems to be an issue on both Firefox and Chrome. Check it out for yourself, and my workaround, here: http:/

Execute web worker from different origin

ぐ巨炮叔叔 提交于 2019-11-29 11:04:01
问题 I am developing a library which I want to host on a CDN. The library is going to be used on many different domains across multiple servers. The library itself contains one script (let's call it script.js for now) which loads a web worker (worker.js). Loading the library itself is quite easy: just add the <script type="text/javascript" src="http://cdn.mydomain.com/script.js"></script> tag to the domain on which I want to use the library (www.myotherdomain.com). However since the library is

Parsing XML in a Web Worker

风流意气都作罢 提交于 2019-11-29 10:34:59
I have been using a DOMParser object to parse a text string to an XML tree. However it is not available in the context of a Web Worker (and neither is, of course, document.ELEMENT_NODE or the various other constants that would be needed). Is there any other way to do that? Please note that I do not want to manipulate the DOM of the current page. The XML file won't contain HTML elements or anything of the sort. In fact, I do not want to touch the document object at all. I simply want to provide a text string like the following: <car color="blue"><driver/></car> ...and get back a suitable tree

How to do worker-to-worker communication?

跟風遠走 提交于 2019-11-29 08:50:39
问题 I'm experimenting with web workers, and was wondering how well they would deal with embarassingly parallell problems. I therefore implemented Connaway's Game of Life. (To have a bit more fun than doing a blur, or something. The problems would be the same in that case however.) At the moment I have one web worker performing iterations and posting back new ImageData for the UI thread to place in my canvas. Works nicely. My experiment doesn't end there however, cause I have several CPU's

Is it possible to run Angular in a web worker?

假如想象 提交于 2019-11-29 07:46:53
I am build a SPA app with angular and I would like to have my Angular service "WebService" shared with a web worker. The objective is to have one "WebService" shared so that I can use the same service in the background (in the web worker) and in the front-end (the angular app). Is this feasible ? Additional info: the idea here is for the synchronisation of data on the remote server, so you have the main app working with an "online|offline" mode, saving the data to the local web-storage and|or to the remote server (using the "WebService") and the worker transparently using the same service to

Does a Firefox Workers limit exist?

那年仲夏 提交于 2019-11-29 07:19:28
Im trying to create web Workers and post messages to them in cycle: array.forEach(function (data) { this.createWorker(); this.workers[this.workersPointer].postMessage({task: 'someTask', data: string}); }, this); createWorker function: createWorker: function () { this.workersPointer++; var worker = this.workers[this.workersPointer] = new Worker('Worker.js'), storage = this; worker.onmessage = function (event) { if (event.data.error) { storage[event.data.task + 'Errback'](event.data.error); } else { storage[event.data.task + 'Callback'](event.data.data); } }; worker.onerror = function (error) {

Why does not Chrome allow Web Workers to be run in JavaScript?

≡放荡痞女 提交于 2019-11-29 05:20:21
If I try to use web workers through a JavaScript file, Chrome throws an error - Uncaught SecurityError: Failed to create a worker: script at '(path)/worker.js' cannot be accessed from origin 'null'. But it allows them if we use directly through the HTML. The answer on Chrome can't load web worker says Chrome doesn't let you load web workers when running scripts from a local file. Why doesn't chrome allow web workers to run locally? Web Workers work completely fine in Firefox, Safari and in Edge Tomáš Zato This question was already asked. The workers should work in HTML files opened from disk