admin管理员组文章数量:1335380
I have got a bug with some javascript code that it's hard to reproduce (so no jsfiddle, sorry). Exactly the same browser (FF 37.0.2), but two different machines, and I can only reproduce the bug on one of them.
I suspect the issue has something to do with localStorage and the fact that I check if an item is there outside $(document).ready().
Is that required? Do I need to wait for the DOM to be ready before reliably accessing localStorage? Is my hypothesis plausible?
I have got a bug with some javascript code that it's hard to reproduce (so no jsfiddle, sorry). Exactly the same browser (FF 37.0.2), but two different machines, and I can only reproduce the bug on one of them.
I suspect the issue has something to do with localStorage and the fact that I check if an item is there outside $(document).ready().
Is that required? Do I need to wait for the DOM to be ready before reliably accessing localStorage? Is my hypothesis plausible?
Share Improve this question asked May 3, 2015 at 0:26 Alessandro CosentinoAlessandro Cosentino 2,3641 gold badge22 silver badges30 bronze badges1 Answer
Reset to default 8localStorage is not something that needs to be "loaded" asynchronously. It is available the moment the page starts to load and can be used by Javascript anywhere in the page. If the browser has to fetch values form somewhere (e.g. the disk), that is done synchronously when you request the data or before.
There is no need to wait with $(document).ready()
before accessing localStorage. The cause of your issue must be something else.
FYI, you can read the spec on WebStorage here: http://dev.w3/html5/webstorage/#dom-localstorage. There is no indication in the localStorage section of that document that JS code must "wait" before accessing.
本文标签: javascriptIs localStorage fully loaded only after DOM is readyStack Overflow
版权声明:本文标题:javascript - Is localStorage fully loaded only after DOM is ready? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344742a2457297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论