web-worker

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

心已入冬 提交于 2019-11-30 09:21:30
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://jsfiddle.net/5ag42hb1/11/ Is this not odd behaviour? Mozilla docs say that Web Workers must obey same

Execute web worker from different origin

爷,独闯天下 提交于 2019-11-30 08:06:19
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 loading a worker from http://cdn.mydomain.com/worker.js new Worker('http://cdn.mydomain.com/worker.js') ,

'Uncaught Error: DATA_CLONE_ERR: DOM Exception 25' thrown by web worker

岁酱吖の 提交于 2019-11-30 07:55:06
问题 So I'm creating a web worker: var arrayit = function(obj) { return Array.prototype.slice.call(obj); }; work = arrayit(images); console.log(work); //work = images.push.apply( images, array ); // Method : "load+scroll" var worker = new Worker('jail_worker.js'); worker.postMessage(work) worker.onmessage = function(event) { console.log("Worker said:" + event.data); }; Here's what images is: $.jail.initialStack = this; // Store the selector into 'triggerEl' data for the images selected this.data(

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

懵懂的女人 提交于 2019-11-30 07:48:48
问题 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

Creating a web worker inside React

北城余情 提交于 2019-11-30 07:16:36
问题 I have a React app created with create-react-app, not ejected. I'm trying to use web workers. I've tried the worker-loader package (https://github.com/webpack-contrib/worker-loader). If I try worker-loader out of the box ( import Worker from 'worker-loader!../workers/myworker.js'; ), I get the error message telling me that Webpack loaders are not supported by Create React App, which I already know. Would the solution be to eject the app (which I'd prefer not to do) and edit the webpack.config

How to do worker-to-worker communication?

半腔热情 提交于 2019-11-30 07:08:52
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 available and would like to parallellize my application. So, to start off simply I split my data in two, down

Global variable in Web worker

ぐ巨炮叔叔 提交于 2019-11-30 06:26:07
问题 I am using this Web worker which has a Global variable declared in it. Can I access the same (Global variable in worker 1) in the newly spawned web worker(worker 2)? When I've tried using jQuery in web worker, I get error "window is not defined". Is there any way to use jQuery in a Web Worker ? importScripts('jquery-latest.js'); function fetch_ajax(url) { $.ajax({ type: 'GET', url: url, success: function(response) { postMessage(response); } }); } fetch_ajax('test.txt'); 回答1: Web Workers don't

How to transfer large objects using postMessage of webworker?

£可爱£侵袭症+ 提交于 2019-11-30 05:27:33
问题 I have read that transferable objects can be transferred really fast using postmessage of web worker. According to this transferable objects are either arraybuffer or messageport. Question is, how do I convert say an arbitrary object that is of large size (30 mb) to a transferable object and pass it as an argument to postmessage. From what I understand I can convert my array to json string and then convert json string to raw byte data and store that inside of an array object. However, this

Detect whether postMessage can send objects?

南楼画角 提交于 2019-11-30 05:20:01
I'm looking for a neat way to detect whether postMessage in the browser supports the sending and receiving of objects or just strings. I figure that someone out there must have wrote something that does this but I have not managed to find a solution. I'm using postMessage to send data to/from a WebWorker. Whilst detecting whether the browser supports workers is straight-forward, detecting whether objects can be send via postMessage has proved more difficult. I'd like to write a simple detection function. So, if the browser supports the sending of objects to use that. If only strings are

Web Workers handling AJAX calls - optimisation overkill?

二次信任 提交于 2019-11-30 04:40:54
I'm working with a code that handles all AJAX requests using Web Workers (when available). These workers do almost nothing more than XMLHttpRequest object handling (no extra computations). All requests created by workers are asynchronous ( request.open("get",url,true) ). Recently, I got couple of issues regarding this code and I started to wonder if I should spend time fixing this or just dump the whole solution. My research so far suggests that this code may be actually hurting performance. However, I wasn't able to find any credible source supporting this. My only two findings are: 2 year