Is it possible in Javascript to have a waiting animation while retrieving from localStorage?

一笑奈何 提交于 2020-01-01 14:39:50

问题


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.



来源:https://stackoverflow.com/questions/17349584/is-it-possible-in-javascript-to-have-a-waiting-animation-while-retrieving-from-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!