Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using web workers in phonegap

I'm trying to create a HTML5 Web Worker in phonegap, but phonegap doesn't allow me to load a local javascript file at runtime. I get the following error:

var web_worker=new Worker('socket-worker.js')
undefined
file://socket-worker.jsFailed to load resource: The requested URL was not found on this server.

Does anyone have a good suggestion on how I can work around this, and get the worker running?

Thanks!

like image 373
asprotte Avatar asked Apr 19 '13 16:04

asprotte


2 Answers

Haven't tried this yet but I believe we can run it using blob url. See it here ( http://www.html5rocks.com/en/tutorials/workers/basics/#toc-inlineworkers-bloburis )

Update: I've tried this already and it worked. :)

like image 63
Nino Paolo Avatar answered Oct 01 '22 13:10

Nino Paolo


As per my knowledge Web Workers never works on local directory

file://

it works on server side. For example instead of placing files at "file://" so the path should be

***> http://localhost/ or***
***> http://server_ip_address***

Hence Phonegap consists of HTML and Javascript which are at device directory hence web workers are not supported in Phonegap.

like image 41
Husain A. Avatar answered Oct 01 '22 15:10

Husain A.