Wiki: Why you should never use Local Storage
For agents: Markdown version · Wiki index · Explore
- Speaker: Ron Hagafny
- Event: Reversim Summit 2024
- Video: https://www.youtube.com/watch?v=uzNambAk9DU
- Transcript: /transcripts/2024/52-uzNambAk9DU.md
- Language: Hebrew · Type: ignite · Level: intermediate
- Topics: Frontend, Databases, Performance
Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.
Summary
The speaker explains the limitations and performance drawbacks of using Local Storage in web applications. The main argument is that Local Storage is synchronous, supports only strings, has a strict storage limit of five megabytes, and is incompatible with service workers. Instead, the speaker recommends using IndexedDB for asynchronous, large-scale storage or utility libraries like LocalForage for an easier migration. The audience learns how to overcome browser storage bottlenecks using modern, robust alternatives.
Key points
- 0:12 The speaker introduces Local Storage, explaining its convenience for persisting user state and improving customer experience since its introduction in 2008.
- 1:24 Local Storage is synchronous and runs on the main thread, which can block JavaScript execution and slow down application loading times.
- 1:24 Local Storage cannot be used with service workers in progressive web apps, and it enforces a strict storage limit of five megabytes per origin.
- 1:24 IndexedDB is introduced as an asynchronous database alternative that integrates properly with browser quotas and supports complex data types.
- 2:38 IndexedDB allows developers to store complex objects, arrays, and even media files like videos for offline use.
- 2:38 Using raw IndexedDB can be overly complex due to its low-level, event-driven API, so wrapper libraries like IDB or LocalForage should be used.
- 3:41 IndexedDB supports creating indexes for efficient querying of stored objects.
- 3:41 LocalForage provides a simple Local Storage-like syntax while leveraging the power of IndexedDB underneath.
Takeaways
- Avoid using Local Storage for complex data structures or large amounts of information to prevent performance bottlenecks and quota exceptions.
- Use IndexedDB when you need asynchronous operations, much larger storage limits, and support for complex data types or offline media.
- Adopt wrapper libraries like IDB or LocalForage to avoid the complexity of the native IndexedDB API while keeping your code clean.
Questions this talk answers
- What are the main performance and capacity limitations of Local Storage in modern web applications?
- How does IndexedDB differ from Local Storage regarding asynchronous execution and storage quotas?
- What libraries can be used to simplify working with IndexedDB while maintaining a simple API?
Technologies
JavaScript, IndexedDB, Local Storage, LocalForage, IDB
Tags
browser storage, frontend, indexeddb, localstorage, performance, web development