web-worker

HTML5/JS - Start several webworkers

守給你的承諾、 提交于 2019-11-28 23:21:22
问题 I'm currently writing on a program, where I have to deal with huge arrays. I can however split those arrays. My plan now is, to process the arrays in different web workers. I have however never worked with them and do have several questions: 1. How would I run several web workers? I tried a for-loop looking like that: for(i = 0; i < eD.threads; i++){ //start workers here var worker = new Worker("js/worker/imageValues.js"); worker.postMessage(brightness, cD.pixels[i]); } Here I do get the

Uncaught ReferenceError: importScripts is not defined

自作多情 提交于 2019-11-28 22:41:41
Why do I keep getting this error? I should be able to use this global function right? http://www.html5rocks.com/en/tutorials/workers/basics/ I'm using chrome. I'm using https://code.google.com/p/bitjs/ and it begins with importScripts('io.js'); importScripts('archive.js'); This code needs to be inside a worker script. The worker itself is created via a new Worker object - see Getting Started in the tutorial . The code you've linked is inside the worker created here . When you create a worker it is actually executed twice. The first pass is in the context of the global 'window' object(meaning

Pass large amounts of data between web worker and main thread

一曲冷凌霜 提交于 2019-11-28 21:24:30
Is there a way to pass large amounts of data (multiple MB) between a web worker and the main thread? I work in a project where I need to download files, modify them a bit and then somehow let the user download the modified file. I found the following ways to pass data between a web worker and the main UI Using the regular postMessage method. Using transferable objects (Chrome only) Create a URL reference to a blob and only send the URL (works in Chrome, in others as well?) I think (1) is fine when sending smaller objects but it takes a lot of time and space when dealing with files larger than

Use ServiceWorker cache only when offline

被刻印的时光 ゝ 提交于 2019-11-28 20:25:23
问题 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(

Using Web Workers for drawing using native canvas functions

一笑奈何 提交于 2019-11-28 19:13:27
It's possible to send a CanvasPixelArray obtained via getImageData to a worker script, and let the worker script manipulate the pixels in its background thread, and eventually post the manipulated pixel array back. However, I'm using native canvas drawing functions, like drawImage . The drawImage calls are currently blocking the UI thread. This causes slow redraw of buttons, and a noticeable delay when clicking on a button, just to name a few drawbacks. (Edit: A small improvement can now be accomplished with ctx.imageSmoothingEnabled = false , at least on WebKit with the webkit prefix.) I'd

Global variable in Web worker

痴心易碎 提交于 2019-11-28 18:39:11
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'); Web Workers don't have a window object. To access global state, use self instead, code that will work on both the main thread

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

白昼怎懂夜的黑 提交于 2019-11-28 10:42:42
问题 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, 回答1: CORS is a specification which has nothing to do with JSONP beyond making it obsolete in newer browsers. It enables

Why won't the client receive new versions of this script in the public folder?

孤街浪徒 提交于 2019-11-28 09:43:23
问题 In my project there is a public folder and a script inside it: public/worker.js , which contains a piece of code: alert('foo'); I call this script using a Worker: new Worker('worker.js'); I launch Meteor and connect to my app. foo is alerted. If I change the public/worker.js code to anything else: alert('bar'); The server refreshes the clients, the client refreshes the page but won't get the new code, instead using the old one (alerting foo instead of the new shiny bar ). Clearing the cache

web worker console.log

最后都变了- 提交于 2019-11-28 09:35:37
Is it just me, or is console.log() too much to ask for from HTML5 web workers? I know that manipulating the DOM is blocked because it is potentially dangerous, but is there really any possibility that console.log() could be maliciously exploited by a multithreaded worker? ebidel Agreed things would be a lot nicer, but it's not too hard to hack up a primitive console.log using postMessage . David Flanagan has a nice wrapper here . Just wanted to post that console.log is now possible atleast within the Chrome Browser. I do not know which version it was added but 35.0.1916.153 m has it.

Opinion about synchronous requests in web workers

依然范特西╮ 提交于 2019-11-28 09:07:16
I want to know what do you think about this. Is recommended to use synchronous requests (XMLHttpRequest) in a web worker? What problems can I find? I have been testing this in my app and I haven't find any trouble. But I'm afraid of this synchronus behaviour because of old experiences with jQuery and AJAX. My app gets a big amount of data from several tables in a database, and this requires a time. For each bunch of data retrieved from a table, I need to instantly process it to not delay the whole thing too much. Meanwhile, the user is interacting with the browser, so it can be blocked, and I