admin管理员组文章数量:1410697
Recently I e across web workers, it's a way to have your scripts run parallel. Giving your script to run in background without "freezing" the user interface. When I found out this, I think I have found a new technique to implement into my ionic app which should bring significant UX performance improvement.
But after some searching, I hardly find any article talk about web workers in ionic. As web workers isn't something very new, why there hardly any mention about it in ionic or even Angular? Is ionic isn't suitable to implement? Or, it is something else that I overlook?
Recently I e across web workers, it's a way to have your scripts run parallel. Giving your script to run in background without "freezing" the user interface. When I found out this, I think I have found a new technique to implement into my ionic app which should bring significant UX performance improvement.
But after some searching, I hardly find any article talk about web workers in ionic. As web workers isn't something very new, why there hardly any mention about it in ionic or even Angular? Is ionic isn't suitable to implement? Or, it is something else that I overlook?
Share Improve this question asked Apr 10, 2016 at 14:32 user1995781user1995781 19.5k45 gold badges139 silver badges241 bronze badges 1- 1 What are you trying to achieve using web workers? – guest271314 Commented Apr 10, 2016 at 14:35
1 Answer
Reset to default 10Will web workers beneficial on ionic app?
That depends entirely on whether you have some heavy processing that you can offload to web workers.
As web workers isn't something very new, why there hardly any mention about it in ionic or even Angular?
Because web workers have nothing to do with UI frameworks, because code in web workers can't directly manipulate the UI of the browser (e.g., can't manipulate the DOM, or do alert
s, play audio, etc.). So web worker code has little-to-no use for a UI framework library, as that library's job is largely to do things the web worker can't do. Instead, there is one main UI thread (the default JavaScript thread for the page) which is allowed to use the DOM and such, and so has reason to use UI framework libraries.
Details:
Originally, JavaScript in web browsers ran on a single thread, which also updated the UI. This made for a very simple model without concurrency issues and was tremendously simple and successful. But it's also limiting: As JavaScript started getting used for more and more things, that one UI thread got bogged down in processing, and browsers had to implement heuristics to do "slow script" warnings and such so the user didn't think the browser had frozen.
Web workers were introduced in order to let us have threads in browser-hosted JavaScript, while keeping the powerful simplicity of the single UI thread without concurrency issues (this is also why they don't share a global data area with other threads). They let us do heavy processing in other threads, but not allowing us to update the UI in those threads.
That work can be indirectly related to UI. For instance, on modern browsers it's possible to send certain kinds of objects, called transferrable objects, from the main UI code to web worker code. IIRC, canvases are transferrable. We get around the concurrency issue because once you post a transferrable object from one thread to another, it's only accessible in the target, not in the source anymore. So the main UI thread, which is allowed to directly interact with the UI, can take something (like a canvas) and transfer it to a web worker to do something to it (a transform, perhaps) and then send it back. But since that work wouldn't involve directly manipulating the browser UI (DOM, etc.), it's unlikely to have much call to use a UI framework library.
本文标签: javascriptWill web workers beneficial on ionic appStack Overflow
版权声明:本文标题:javascript - Will web workers beneficial on ionic app? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744282496a2598721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论