Is it possible in Javascript to have a waiting ani

2019-04-11 13:00发布

Understanding that the Javascript localStorage API is synchronous and thus blocking, is there any workaround that would allow one to display a waiting animation that doesn't freeze during the getItem() or setItem() operations?

2条回答
看我几分像从前
2楼-- · 2019-04-11 13:18

If getting 300kB of data from local storage and parsing it with JSON.parse is too slow for a single synchronous blocking operation, you will have to split it up in smaller chunks. Those can be stored in single storage slots and shell be processed in an asynchronous loop (see also JavaScript Performance Long Running Tasks, How to stop intense Javascript loop from freezing the browser).

查看更多
Summer. ? 凉城
3楼-- · 2019-04-11 13:33

You can make any synchronous operation, including localStorage, asynchronous by using Web Workers.

查看更多
登录 后发表回答