I am considering using localStorage to store recent searches.

- Privacy friendly, backend doesn't track what you search
- Quicker to load results for previous searches

- I can't think of any. If you can, please reply to this post!

· · Web · 9 · 6 · 15

@dansup how does it sync between a mobile client and a web browser?

@paperdigits I don't feel comfortable logging searches, and that would be required to sync between browsers and apps.

@dansup I understand and appreciate the attention to detail and respect for privacy.

@dansup localStorage is synchronous, loads all content into memory on page navigation (in FF at least), and is capped at 5MB in some browsers. It's good for small data, but you may want to use IndexedDB instead.

@dansup Heads up: I can't remember if it's local storage or another tool, but there is some wonky behavior with private mode on Firefox that I hit when I try to use Standard Notes.


localStorage has size constraints (5 to 10MB, possibly a bit more) and can only handle strings.

@dansup Downside: Safari is very aggressive about attempts to access localStorage in incognito, so you need to try...catch _everything_. If you write a little wrapper for it, it works out pretty okay.

The API also isn't wonderful, but you can wrap that too and make it nicer.

@dansup is a pretty good option for wrapping localStorage (and indexeddb and websql).

@zacanger Cool thanks, I'm using typeahead/bloodhound and think it has a localStorage cache.

@dansup It does, and it looks like they safely check if it can be accessed, which means you won't see a bunch of "SecurityError: DOM Exception 18" from folks on Safari in private mode

a) if that''s the only thing you use it for, you'll need to add a GDPR cookie warning just for that
b) if new content related to the search term becomes available, it will not be shown in the cached results

@dansup If you use localStorage, it won't be accessible if a Service Worker comes in your app at some point (which is rather likely to happen). IndexedDb would by my first choice (with for simple use cases). Also, this read is worth it:

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!