Is It Possible To Optimize Two Scripts Using Web Workers?
Solution 1:
If one or both of the scripts is/are purely functional, meaning it doesn't need to access the DOM or any global Javascript objects, then you could benefit from using Web Workers.
If this is not the case, then Web Workers will do you no good. When JS is run through a web worker, it can only pass messages back to the main DOM thread and receive them.
Solution 2:
No, javascript is executed on a single thread in the web browser. So you cannot run them in parallell unless they are not user interactive (does not interact with the DOM).
However, you can LOAD the script asynchronously to speedup initialization.
Simply use the async=true
attribute on <script>
. Like this:
<scriptasync="async">....</script>
Solution 3:
As I understand them, web workers afford you an OS-level thread of execution. So performance improvements are likely dependent on the tradeoffs inherent in the client OS's threading implementation.
In any case, you should see an improvement in load times unless the OS has a terrible threading implementation.
Solution 4:
My bet, YES.
Its like asking
1 man takes 6 days to do a task. How much time will 2 men take?
:-)
Most ideal use-case for WebWorkers
Post a Comment for "Is It Possible To Optimize Two Scripts Using Web Workers?"