What happens if the write to localStorage is canceled?

Let's say I'm calling local storage, for example:

window.localStorage.setItem("key", bigJsonObject); 

And right after that, the user closes his web browser. What will be the result

 window.localStorage.getItem("key") 

Will bigJsonObject be partially written? Or will lose the whole record? Their way to guarantee that there will be no partial recording?

+5
source share
1 answer

Refer to & sect; 4.1 specifications of "web storage" :

The setItem() and removeItem() methods must be atomic with respect to failure. In the event of a failure, the method does nothing. That is, the changes in the data storage area must be either successful, or the data storage area should not be altered at all.

However, there are (historically) browser errors in this regard, for example. some time until Chrome 21 until some time before Chrome 29 .

+5
source

Source: https://habr.com/ru/post/1210505/


All Articles