News for hackers. Stuff that matters.
Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Sunday December 15, 2019 @12:37PM (#21797503)
i still don't understand the core issue: why is anyone saving essential data to localstorage? isn't that supposed to be a state-related, somewhat temporary (due to its nature) storage in-between the UI and the API/database? don't you lose all your data when you use a different pc or smartphone?

i see a lot of mentions of cordova apps. are people publishing apps without a backend (and save everything in localstorage)?

i've worked on pwa's in the past but server sync was always a priority in my algorithms.

does anyone have any realistic use cases where localstorage is so essential that clearing it would somehow lose tons of data?

Re:LocalStorage or WebSQL unexpectedly cleared by capableweb on Sunday December 15, 2019 @12:46PM (#21797591)
Depends on the context. I've built Cordova/Phonegap apps in the past where you want things to work offline and sync once the user goes online. If the time from user going offline to online again is too long / device storage too little, that data that would eventually need to be synced, would be lost.

Always ways of working around it, like saving to files or whatever, but localStorage is a nice interface that works both for Cordova and client-side web apps.

Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Sunday December 15, 2019 @03:17PM (#21798693)
agree. for the use case that you mentioned there would be a problem.

but as you said, it could be overcome by using native apis that store state. it's even imperative in case of secrets, like access tokens and the like.

for client side web apps there's a bigger problem with localstorage. from my experience end users switch browsers and platforms. and they expect consistency from their web sites/apps. this expectation is much more intense than for native apps. so, while practical for developers, i'm not sure it's that welcomed in web land except for always having a local backup or as a temporary storage to alleviate network issues.

Re:LocalStorage or WebSQL unexpectedly cleared by zmzrr on Sunday December 15, 2019 @02:20PM (#21798294)
>i see a lot of mentions of cordova apps. are people publishing apps without a backend (and save everything in localstorage)?

Yes. Why not? You can write a Cordova app that doesn't even have a backend.

Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Sunday December 15, 2019 @03:06PM (#21798622)
of course you can.

but since every device is as persistent as its weakest point (e.g. physical damage, loss/theft, etc) shouldn't apps that need to save essential/important data basically give up the argument of persistence because of using localstorage in the first place? your data is one breakdown/loss away from permanent destruction when using localstorage exclusively.

that is why, from my experience, you always rely on the server and only use localstorage as a backup in case the server is down, there's no internet, etc.

claiming massive loss of data because localstorage got emptied is basically saying "our app wasn't designed correctly".

what am i missing?

Re:LocalStorage or WebSQL unexpectedly cleared by zmzrr on Sunday December 15, 2019 @03:12PM (#21798666)
If my phone breaks, I lose my data, and that is my responsibility. You are saying that everything should be backed up on the cloud, I think that's crazy.

localstorage disappearing overnight IS a bug. If I put stuff in My Documents folder on Windows and Windows decides to delete it, that IS a bug too. You could argue that I should have backups, and you would be right, but that's no reason for Windows to delete my files, and that is no reason for me to never use my hard disk.

Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Sunday December 15, 2019 @03:33PM (#21798793)
of course not everything should be backed up to the cloud. but if it's important and only available on your phone, then yes please back it up, or better yet, have it up there in the cloud.

regarding your comparison between a windows folder and localstorage feels a bit exaggerated.

yes, the Chrome team really fumbled it. and yes localstorage and important data should be mutually exclusive.

Re:LocalStorage or WebSQL unexpectedly cleared by tsimionescu on Monday December 16, 2019 @01:01AM (#21801092)
You're right that important data needs to be backed up, but I disagree that it is the app builder's responsibility to do that. It is the end-user's responsibility to think about backups, to choose where to backup and how often. From the app developer's perspective, it is commendable that, in this day and age, they allowed users to retain control of their own data, instead of automatically uploading the user's data to the developer's server.

Local storage and/or SQL DB were touted as features for exactly this use case. That Google did not consider their persistence as that important for the release is perhaps not surprising for a company used to storing all your data in their cloud (not claiming they did so knowingly, just that it's probably in their culture, just as in your comments above).

Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Monday December 16, 2019 @04:30AM (#21801875)
interesting take. i agree with it in spirit.

but unfortunately i don't think your average user has any idea about what you wrote.

Re:LocalStorage or WebSQL unexpectedly cleared by jessaustin on Monday December 16, 2019 @06:51AM (#21802400)
...localstorage and important data should be mutually exclusive.

It seems like we could say "don't trust this" about any aspect of any platform. Categorizing every application as "really important, don't update the UI until securely written to three AZs" and "totally ephemeral purge every minute" excludes a lot of stuff in the middle. Sure, nothing made by humans is perfect, but many things could be improved. One improvement to localstorage would be to simply not delete all the data.

Re:LocalStorage or WebSQL unexpectedly cleared by WA on Monday December 16, 2019 @03:59AM (#21801746)
Are you serious? Maybe you missed the entire privacy conversation around cloud storage in the last couple of years. Also, with your reasoning, your entire laptop should merely be a client for a remote storage.

Saving stuff locally is good for privacy, for performance, for offline-capabilities. You can back up your entire phone LOCALLY, to have a solution of your stated problems (theft, physical damage).

Re:LocalStorage or WebSQL unexpectedly cleared by kmlx on Monday December 16, 2019 @04:29AM (#21801862)
i am very serious. people lose their devices all the time.

never save important data on a single device. you simply delay the inevitable "i lost my data" scenario.

non-important data on the other hand should have no problems living on a single device. or even localstorage.

and as i said before, i don't think your average user has any ideas about backing up. that's why it almost always comes back to the developers to implement it.

Re:LocalStorage or WebSQL unexpectedly cleared by apatheticonion on Sunday December 15, 2019 @11:45PM (#21800867)
I wrote a PWA which functioned as a calories counter and exercise tracker.

I stored the data on the client using indexedDB, offering an export/import option for manual backups.

I wasn't interested in the data and it's simpler to just store it on the client rather than setting up the infrastructure required to centrally persist this information.

It's really unfortunate that it's not a reliable storage medium.

Re:LocalStorage or WebSQL unexpectedly cleared by gnaritas on Monday December 16, 2019 @02:15AM (#21801314)
> It's really unfortunate that it's not a reliable storage medium.

That's not what it's for, you're just misusing the tool for something it isn't meant to be. It's not a database, it's a cache.

Re:LocalStorage or WebSQL unexpectedly cleared by londons_explore on Monday December 16, 2019 @09:59AM (#21803421)
In today's GDPR world, a lot of companies want to see as little of the users private data as possible.

If their app can avoid sending any data to a server and run fully in a web browser offline, they'll do that.