I'm using local storage to store some data: the user makes ajax requests to get information and I'm storing the result in storage so that next time he requests the same info, I first look in storage to see if it's there.
Now I'm realizing it's actually more efficient to keep that data in an object in memory, and loop over that when needed, rather then loop over local storage. So as I'm moving some data from local storage to an in-memory object, I'm wondering if the window.unload event can be reliably used to write the content of that cache object to local storage on disk, and then retrieve it back using the onload event?
Thanks.
window.unload
may not be invoked under a number of circumstances, for instance if the user closes the tab or if the browser crashes. Why not save the data to localStorage periodically, as a precaution?
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