Does iframe runs on the same thread as the owner?

前端 未结 2 1975
一生所求
一生所求 2021-01-17 15:37

I have a CPU intensive work to do and i don\'t want to degrade the user experience. since web workers (http://ejohn.org/blog/web-workers/) are a new feature and are not supp

2条回答
  •  失恋的感觉
    2021-01-17 16:01

    One way to sort of simulate multi-threadedness would be to have a Javascript function do a little bit of work, then call setTimeout with that same function; then the function will do a little work and call setTimeout again, and this cycle will continue forever or until they close the frame or you signal to stop working. MDN has a good example of how to set this up.

    Between timeouts, Javascript should not consume any processor time. You might have to play around a little bit to see how long your timeouts should be -- 1ms is probably way too short, but 1s is definitely way too long. Another factor will be the processor speed of the computer running the job, so you might need to do some pseudo-benchmarking on the client's side via Javascript before you can determine how long to delay each time.

提交回复
热议问题