admin管理员组文章数量:1406334
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?
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?
- 3 start animation before storage operation. do storage operation(s). stop animation? – Marc B Commented Jun 27, 2013 at 17:27
- At least the way I've tried it, the animation freezes during the storage operation. – AR. Commented Jun 27, 2013 at 17:29
-
1
What kind of storage are you talking about then? Simply using
localStorage.setItem()
? Is it a large amount of data? Do you have to serialize it? Are you doing something separate that is synchronous that blocks the page? – Ian Commented Jun 27, 2013 at 17:30 - Yes, very simple calls to localStorage.setItem() and getItem(). Yes, serialization is necessary. It's probably ~300kb of data. I can't think of anything else that would be blocking, except possibly the JSON.parse() call when deserializing. – AR. Commented Jun 27, 2013 at 17:49
- What type of animation did you use, a javascripted one? You could try CSS animations or animated GIFs, which might run in a separate thread (depending on browser though). – Bergi Commented Jun 27, 2013 at 17:59
2 Answers
Reset to default 4If 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).
You can make any synchronous operation, including localStorage, asynchronous by using Web Workers.
本文标签:
版权声明:本文标题:local storage - Is it possible in Javascript to have a waiting animation while retrieving from localStorage? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744991005a2636385.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论