Live data from Hacker News

Don't rely on LocalStorage

blog.jacobweisz.com

51–60 of 71 posts

Re: Don't rely on LocalStorage

#51
This is one of the big missing pieces of the web development puzzle. It would be quite nice if the browsers handled sync & backup of local data. Would be even better if came with SQL access.

Re: Don't rely on LocalStorage

#52

> LocalStorage is popular for web apps because it is lazy No... localStorage is popular because it allows you to persist state without requiring a server, opening up a whole lot of use cases that would normally require a login. With the tradeoff that you can't easily sync between machines and it can be cleared readily. Calling it "lazy" seems bit unnecessarily confrontational. Of all the times I have used localStorag…

LocalStorage serves important use-cases - you mentioned a few - but I‘be seen it used a bunch in web apps, where the user is already logged in, to persist setting. It was easier than adding an API to store a user‘s UI settings/state.

True. Not only easier but often times that user wants different settings on different machines (or even different browser profiles). What I want in my settings on my mobile device is not always the same as desktop especially when it comes to visual settings.

Re: Don't rely on LocalStorage

#54

How can they migrate it to server without requiring login? The best part is that you don't need to create any user for playing. Accessing data between devices requires some form of auth.

I would assume almost all daily users of Wordle would consider having to have an account in exchange for persistent, cross-device statistics a worthy trade-off. And presumably a well-designed app could even abuse LocalStorage for anonymous play, and include a mechanism to hand off and save your data, should you wish to, via a login. Social OAuth and passwordless email login (essentially one-time codes) are both prett…

To be fair, I think you're probably right. But, that doesn't make the article any more right to me. The argument wasn't that local storage is no longer a good choice, but that it's always a bad choice. Or at least that's how it comes across to me.

Re: Don't rely on LocalStorage

#55
post #12
post #3

Regarding Wordle specifically, this allowed Josh Wardle to make the app a simple webpage with no backend necessary beyond serving the page itself. Is there something that allows someone like him to do that aside from LocalStorage?

I believe he could have used Cookies instead of LocalStorage. The data he's keeping seems simple enough. It has the same issues the author is talking about, but it should work.

Can client-side code set the cookies themselves? I was under the impression cookies were a HTTP-level thing.

Re: Don't rely on LocalStorage

#56
I imagine Khaby Lame sitting at a desk, a laptop, a tablet, a printed out sandstorm logo and a phone next to him. He puts the laptop, logo and tablet away, grabs the phone and points at it several times, his facial expression saying:

"If you want your stats proper and orderly, play the game only from your phone, buddy."

Re: Don't rely on LocalStorage

#57

> Ultimately, people should have control of their data, and they should have access to their data from all of their devices. Whether that is running their own or renting someone else's, that ultimately means the correct place to store web app data is on a server. Hrm. But I don't have control of my data on a server. The person running the server does. There is currently no good way to satisfy both of these conditions…

I specifically refer to self-hosting here, which does satisfy both of those conditions. (There is arguably still a lot of stress to making self-hosting a better experience for non-technical users, and unfortunately large tech companies are very motivated to maintain a paradigm opposed to self-hosting.) But I also do not feel LocalStorage is really a good way to ensure you have control of your data: It's very unlikely…

> But I also do not feel LocalStorage is really a good way to ensure you have control of your data: It's very unlikely you (or most anyone else) are auditing the code of a site to ensure it maintains your data locally, much less ensure that doesn't change over time.

There's nothing in this critique that doesn't also apply to hosted (server-based) storage.

If anything, it's harder to do those things with servers, because (a) if you the user are truly paranoid, it's trivial to throw a switch and make sure that no data is getting out—by shutting off your network connection entirely, whereas with server-based storage for user data the user has to do some form of whitelisting or blacklisting, and (b) it's pretty straightforward to get all your data at any given time, esp. since the localStorage API is well-defined, whereas if the application author had started with a server-based approach, it probably would have been a server under their control and not yours, which means your best shot involves either intercepting all communications from the beginning (instead of after the fact, once you realize you're interested in it) or doing the legwork to figure out the protocol and issue the appropriate request(s) to get all of it (rather than just a view), if that's even possible.

Overall, I don't think this post makes a very forceful argument that localStorage is bad, only that there might be a better experience for users if all the following conditions hold true:

1. they're playing across multiple devices

2. they're willing to take the time to connect to remote storage

3. the developer behind the app is sympathetic to the cause of data portability and/or user-controlled data, and is therefore willing to implement the necessary integration to enable #2

Failing that, a world where developers are defaulting to localStorage is still a much better state of affairs than what's typical of application authors today.

Re: Don't rely on LocalStorage

#58
post #14

Sure you won't be able to see all of your friend's stats in one nice looking UI, but I doubt that has bothered anyone tremendously. If anything, what you perceive to be crutch actually encourages people to share their result 1-1 with their friends in whatever chat apps they please. That to me, is a feature, not a bug.

Yeah, keeping stat sharing outside of the app serves as user-generated marketing. I think that counts more as a feature for the dev than the user, though.

Re: Don't rely on LocalStorage

#59
post #7

How can they migrate it to server without requiring login? The best part is that you don't need to create any user for playing. Accessing data between devices requires some form of auth.

Many auth providers allow anonymous auth, which creates a UID that can be used to store and secure data. Only later the customer can link that account with another identity provider (e.g. socail, email/password). This gives the low-friction benefits of local storage and the flexibility of cloud storage.

I have found firebase to be a pretty good provider if you want something to get going quickly with. There are lots of others too, but it's probably got one of the more generous free tiers. But something to beware of is potential lock-in and loss of user privacy. Also, some of the free tiers are pretty generous, but then they hit a cliff and it can be expensive quickly. That could be a bad thing if you want to build a free app that goes viral. Also, not all of the providers also provide the cloud storage, so you might have to build/pay for that. Lots of drawbacks to this design choice that would not be suitable for a high user, free app run by an indie developer.

Re: Don't rely on LocalStorage

#60

How can they migrate it to server without requiring login? The best part is that you don't need to create any user for playing. Accessing data between devices requires some form of auth.

I would assume almost all daily users of Wordle would consider having to have an account in exchange for persistent, cross-device statistics a worthy trade-off. And presumably a well-designed app could even abuse LocalStorage for anonymous play, and include a mechanism to hand off and save your data, should you wish to, via a login. Social OAuth and passwordless email login (essentially one-time codes) are both prett…

> I would assume almost all daily users of Wordle would consider having to have an account in exchange for persistent, cross-device statistics a worthy trade-off

Not for me, absolute deal-breaker. My fingers would find ctrl-w before the "Log in with Facebook!" modal finishes rendering.

Post reply on HN