Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web workers in mobile browsers

I am working on a mobile application that needs to poll a web service on a regular interval (using setInterval). I have made a prototype based on HTML5, but when the mobile browser goes in the background, javascript execution is suspended.

I looked into creating native apps for iOS and Android. On iOS this can be done by asking for a limited amount of processing time when the application enters background mode. On Android I guess I would have to make a service that is started and stopped from the application.

However, I see that in Safari on iOS5, web workers support is back, and that this has already been supported in the Android browser for a while. This makes me wonder, can I use web workers to run javascript in the mobile browsers when they are in the background?

like image 665
Jørgen Avatar asked Sep 05 '11 11:09

Jørgen


People also ask

Do web workers work on mobile?

The answer is no. Unfortunately background applications with HTML5 technologies is no go for mobile. Not only mobile browsers aggressively suspend the page when it is background, but they also can kill the whole browser (tab) if they feel so. Whether you have or have not web workers does not affect this.

Are web workers supported in all browsers?

Worker ? Internet Explorer 10, Firefox, Chrome, Safari and Opera support Web workers.

What are web workers example?

Common examples of web workers would be: Dashboard pages that display real-time data such as stock prices, real-time active users, and so on. Fetching huge files from the server.

What are web workers?

Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface.


1 Answers

The answer is no.

Unfortunately background applications with HTML5 technologies is no go for mobile. Not only mobile browsers aggressively suspend the page when it is background, but they also can kill the whole browser (tab) if they feel so. Whether you have or have not web workers does not affect this.

Running even native applications on background is not trivial on these operating systems.

What I suggest you is that

  • Extract background worker part out of your JS and write it in native language (Java, iOS)

  • Use Phonegap etc. similar wrapper for your application UI

like image 200
Mikko Ohtamaa Avatar answered Oct 03 '22 09:10

Mikko Ohtamaa