Is it possible in Javascript to have a waiting ani

2019-04-11 12:42发布

问题:

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?

回答1:

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).



回答2:

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