# Why you should never use Local Storage

- Speaker: [Ron Hagafny](/wiki/speakers/ron-hagafny.md)
- Event: [Reversim Summit 2024](/wiki/years/2024.md)
- Video: https://www.youtube.com/watch?v=uzNambAk9DU
- Transcript: [/transcripts/2024/52-uzNambAk9DU.md](/transcripts/2024/52-uzNambAk9DU.md)
- Language: Hebrew · Type: ignite · Level: intermediate
- Topics: [Frontend](/wiki/topics/frontend.md), [Databases](/wiki/topics/databases.md), [Performance](/wiki/topics/performance.md)

> 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](https://www.youtube.com/watch?v=uzNambAk9DU&t=12s) The speaker introduces Local Storage, explaining its convenience for persisting user state and improving customer experience since its introduction in 2008.
- [1:24](https://www.youtube.com/watch?v=uzNambAk9DU&t=84s) Local Storage is synchronous and runs on the main thread, which can block JavaScript execution and slow down application loading times.
- [1:24](https://www.youtube.com/watch?v=uzNambAk9DU&t=84s) 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](https://www.youtube.com/watch?v=uzNambAk9DU&t=84s) IndexedDB is introduced as an asynchronous database alternative that integrates properly with browser quotas and supports complex data types.
- [2:38](https://www.youtube.com/watch?v=uzNambAk9DU&t=158s) IndexedDB allows developers to store complex objects, arrays, and even media files like videos for offline use.
- [2:38](https://www.youtube.com/watch?v=uzNambAk9DU&t=158s) 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](https://www.youtube.com/watch?v=uzNambAk9DU&t=221s) IndexedDB supports creating indexes for efficient querying of stored objects.
- [3:41](https://www.youtube.com/watch?v=uzNambAk9DU&t=221s) 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
