Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, I wouldn't trust localStorage to survive for long.


I'm surprised no one is mentioning IndexedDB [0] Seems like a well-supported [1] document database built into the browser would beat LocalStorage in almost every way. That's what I've found in my experience at least.

[0] https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_A... [1] https://caniuse.com/indexeddb


It survives pretty well. I built a super basic localStorage only web app and it's worked really well. Until I switched phones and realized I didn't add export functionality.


I simply added a local storage inspector bookmark to my chrome profile, so it gets sync to all devices. Now on any page, I just need to type its name, it will appear in dropdown, & clicking it exports all local storage used by current page or domain as json file.

Code of bookmarklet:

javascript:(function() { var backup = {}; for (i = 0; i < localStorage.length; i++) { var key = localStorage.key(i); var value = localStorage.getItem(key); backup[key] = escape(encodeURIComponent(value)); } var json = JSON.stringify(backup); var base = btoa(json); var href = 'data:text/javascript;charset=utf-8;base64,' + base; var link = document.createElement('a'); link.setAttribute('download', 'backup.json'); link.setAttribute('href', href); document.querySelector('body').appendChild(link); link.click(); link.remove();})()


from experience, I wouldn't trust any of the web storage APIs. they can survive for a long time, but your data can get corrupted.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: