Choosing the Right Client-Side Storage

Client-side storage turns the browser into a mini-database for faster loads and offline access. It's used for remembering user preferences or caching assets.
Why it exists
Modern websites need to maintain state and provide rich experiences without constantly fetching data from a server. Client-side storage was created to solve this by allowing web applications to store data directly on a user's computer. This enables personalization, offline functionality, and significant performance improvements by reducing network requests.
The mental model
Think of client-side storage as a small filing cabinet next to your desk (the browser) instead of a massive warehouse downtown (the server). For frequently used files or personal notes, the local cabinet is much faster and works even if the road to the warehouse is closed. You have different drawers for different needs: a simple key-value drawer (Web Storage), a structured file index (IndexedDB), and a box for offline copies of assets (Cache API).
How it works
Browsers provide several JavaScript APIs to manage local data. The Web Storage API offers localStorage and sessionStorage for simple string-based key-value pairs. For more complex needs, the IndexedDB API provides a transactional database inside the browser, allowing you to store large amounts of structured data and query it efficiently. For offline applications, the Cache API, often used with Service Workers, lets you explicitly store network responses (like CSS files, images, and API data) and serve them directly from the cache.
When to use it
Use client-side storage for three main scenarios. First, personalizing a user's experience, like saving their preferred theme or language. Second, persisting application state, such as the contents of a shopping cart or remembering a login across browser sessions. Third, for performance and offline capability, by caching application assets and data so the site loads faster and can function without a network connection.
When not to use it
Avoid client-side storage for sensitive data like unencrypted tokens, as it can be accessed by any script on the page. It is not a replacement for a server-side database when data must be authoritative, secure, and accessible across a user's different devices. All client-side storage is limited in size, with quotas varying by browser, making it unsuitable for massive, ever-growing datasets.
One canonical example
A web-based music player downloads a user's playlist. Instead of re-downloading the audio files on every visit, it stores them in a client-side database like IndexedDB. On subsequent visits, the application checks the local database first. If the files are present, it plays them directly from the user's machine, saving bandwidth and providing a faster, offline-capable experience.
Interview question
A developer needs to store data in a web application. For which scenario would client-side storage be the LEAST appropriate choice?
- a.Saving a user's language preference for faster loading
- b.Maintaining the contents of a shopping cart across sessions
- c.Storing a user's unencrypted password for automatic loginCorrect
- d.Caching large video files for offline playback
Why? this is the answer
The card explicitly states to avoid client-side storage for sensitive data like unencrypted tokens due to security risks. Caching large assets for offline use, saving preferences, and persisting shopping cart contents are all appropriate uses of client-side storage.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
- #web apis
- #browser
- #storage
- #performance
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on web apis — each one lists the topics its interview covers.
See open roles