The Client (Side) Is Always Right

I think we’ve reached “peak cloud.” Marketers are running around pitching it like a Ginsu knife: It stores all of your data securely! It’s cheap! It’s accessible anywhere! And wait, there’s more!

Sounds great, but I don’t want all of my personal data on remote servers. Cloud APIs come with rate limits and per request pricing adds up. And on slow or intermittent connections, the cloud is more hinderance than help.

Enter client-side storage. Although it’s limited to a few megabytes per domain, it can help you speed up your app by storing user-specific data locally. That way you don’t have to make a new API call every time you launch a new tab or refresh the page.

Building on the existing HTML5 localStorage API, Matthew Riley MacPherson has created an asynchronous, multi-protocol interface for client-side storage called localForage. No matter what storage engines your browser supports — localStorage, IndexedDB, WebSQL — it will pick the best one for you and wrap it up with promise & callback support.

So now, you can store and persist data for your app, on/off-line, with a single method. And since localForage automatically handles input/output serialization, you can use it for images, numbers, HTML, text, or whatever.

Check it out for yourself in my scratchpad demo. Write a note, save it, and then refresh the page or clear the text area. You can reload the note by clicking revert, even across browser sessions.


Revert   Save   Clear


Join the discussion

2017 Neal Shyam