Let's say I make a call to local storage like so:
window.localStorage.setItem("key", bigJsonObject);
And immediately afterwards, the user closes their web browser. What will be the result of
window.localStorage.getItem("key")
Will the bigJsonObject
be partially written? Or will the whole write fail? Is their any way to guarantee that there will be no partial writes?
Refer to §4.1 of the "web storage" specification:
The
setItem()
andremoveItem()
methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all.
However, there have (historically) been browser bugs in this regard, e.g. some time before Chrome 21 until some time before Chrome 29.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With