Javascript

QuotaExceededError Dom exception 22 An attempt was made to add something to storage that exceeded the quota

19 September 2026 · 8 min read

QuotaExceededError Dom exception 22 An attempt was made to add something to storage that exceeded the quota

Encountering errors while developing web applications can be frustrating, especially when they involve storage limitations. One common issue developers face is the QuotaExceededError, often seen as “DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.” This error arises when your web application tries to store more data in the user’s browser storage (like localStorage or sessionStorage) than the browser allows. Understanding the root causes of this error and how to effectively manage browser storage is crucial for building robust and user-friendly web applications. Failing to address this can lead to data loss, application crashes, and a poor user experience. We’ll explore the reasons behind this error, practical troubleshooting steps, and best practices to prevent it from occurring in your projects.

Understanding the QuotaExceededError

The QuotaExceededError (DOM Exception 22) is a browser-generated error that occurs when a web application attempts to store data exceeding the storage quota allocated to that origin. Browsers impose these limits to prevent malicious websites from consuming excessive storage space on a user’s device. This protects user privacy and ensures fair resource allocation. The error typically manifests when using web storage APIs such as localStorage, sessionStorage, or even IndexedDB. It’s essential to understand that the quota is per origin, meaning it’s specific to the domain and protocol of the website.

Several factors contribute to this error. Firstly, the storage quota varies between browsers and can depend on the available disk space on the user’s device. Secondly, the size of the data you’re trying to store matters significantly. Larger strings, complex objects, or numerous small items can quickly fill up the available storage. Finally, browser settings or extensions might interfere with storage operations, inadvertently triggering the error. For example, a user might have configured their browser to limit storage usage for specific websites or clear storage on exit. According to a study by Mozilla, the default localStorage quota is typically around 5MB per origin, but this can vary.

Here’s a featured snippet-optimized paragraph: The QuotaExceededError signals that your web application has attempted to write more data to the browser’s storage (localStorage, sessionStorage, IndexedDB) than is permitted by the browser’s quota for that website’s origin. Browsers enforce these quotas to safeguard user devices from excessive storage consumption by individual websites, maintaining overall system performance and user privacy. Understanding the limits and managing storage efficiently is key to preventing this error.

Troubleshooting the QuotaExceededError

When encountering the QuotaExceededError, a systematic troubleshooting approach is essential. Start by inspecting the code responsible for writing to the browser storage. Use the browser’s developer tools to identify the exact line of code where the error occurs. This helps pinpoint the storage operation that exceeds the quota. Next, verify the size of the data being stored. Large strings or complex objects can quickly exhaust the available storage. Consider compressing data before storing it or breaking it into smaller chunks.

Another crucial step is to monitor storage usage. Most browsers offer developer tools that allow you to inspect the contents of localStorage and sessionStorage. This provides valuable insights into the amount of data being stored and helps identify potential storage hogs. Regularly clearing unnecessary data can also prevent the error. Implement mechanisms to remove outdated or irrelevant data from storage. For example, you could set expiration dates for cached data and automatically delete it after a certain period. Remember to test your application thoroughly in different browsers to ensure consistent behavior. Each browser has its nuances regarding storage quotas and error handling. You can test in Chrome, Firefox, and Safari to catch any browser-specific issues. Effective error handling is critical, so your application can gracefully manage the error and inform the user if needed.

According to a Stack Overflow survey, a significant percentage of developers have encountered the QuotaExceededError, highlighting its prevalence and the importance of understanding how to address it. Proper debugging and proactive storage management are key to preventing this error and ensuring a smooth user experience.

Best Practices for Preventing QuotaExceededError

Preventing the QuotaExceededError requires a proactive approach to storage management. One fundamental practice is to minimize the amount of data stored in the browser. Only store essential data and avoid caching large, unnecessary files. Compress data before storing it to reduce its size. Compression algorithms like gzip or deflate can significantly reduce the storage footprint of strings and objects. Be mindful of the data types being stored. Storing numbers or booleans as strings can increase their storage size unnecessarily.

Implement a data eviction policy to remove outdated or irrelevant data from storage. Set expiration dates for cached data and automatically delete it after a certain period. This ensures that the storage doesn’t accumulate unnecessary data over time. Use pagination for large datasets. Instead of storing the entire dataset in the browser, load and store data in smaller chunks as needed. This reduces the initial storage footprint and improves performance. Regularly monitor storage usage using the browser’s developer tools. This provides valuable insights into the amount of data being stored and helps identify potential storage hogs. Consider using IndexedDB for storing large amounts of structured data. IndexedDB offers more storage capacity than localStorage and sessionStorage and provides better performance for complex data operations. Mozilla Developer Network provides extensive documentation on IndexedDB.

Here are some key points to remember:

  • Minimize the amount of data stored.
  • Compress data before storing.
  • Implement a data eviction policy.
  • Use pagination for large datasets.
Infographic here showcasing storage limits in different browsers.
Alternative Storage Solutions -----------------------------

When browser storage limitations become a bottleneck, consider alternative storage solutions. Server-side storage is an option when dealing with large datasets or sensitive information. Store data on the server and retrieve it as needed using API calls. This allows you to bypass browser storage limits and provides more control over data security. Cloud storage services like Amazon S3, Google Cloud Storage, or Azure Blob Storage offer scalable and cost-effective solutions for storing large amounts of data. These services provide robust APIs for uploading, downloading, and managing data.

Another alternative is to use cookies strategically. Cookies can store small amounts of data and can be used to track user preferences or session information. However, be mindful of cookie size limits and privacy implications. Caching strategies can also help reduce the need for browser storage. Use a Content Delivery Network (CDN) to cache static assets like images, CSS files, and JavaScript files. This reduces the load on the server and improves performance. For larger datasets, consider using a database like SQLite or PostgreSQL on the server. These databases offer robust data management capabilities and can handle large amounts of structured data efficiently. Amazon S3 is a widely used cloud storage solution.

Choosing the right storage solution depends on the specific requirements of your application. Consider the size of the data, the frequency of access, the security requirements, and the cost. Carefully evaluate the trade-offs between browser storage, server-side storage, and cloud storage to determine the best approach.

  1. Assess your storage needs.
  2. Evaluate browser storage limits.
  3. Consider server-side or cloud storage.
  4. Implement caching strategies.

FAQ About QuotaExceededError

What exactly does "DOM Exception 22" mean?
DOM Exception 22, also known as `QuotaExceededError`, indicates that a web application has attempted to store more data in the browser's storage than the browser's quota allows for that specific website's origin (domain and protocol).
How can I check the storage quota in different browsers?
You can't directly query the exact quota limit through JavaScript, as it varies between browsers. However, you can attempt to write data and catch the `QuotaExceededError` to infer the limit. Browser developer tools (e.g., Chrome DevTools) often display storage usage information.
Is there a way to request more storage from the browser?
No, you cannot directly request more storage. The browser determines the storage quota based on various factors. Your application must manage storage efficiently within the allocated limits. Using IndexedDB can provide more storage space than localStorage in some cases.
What are some common causes of the `QuotaExceededError`?
Common causes include storing large amounts of data in localStorage or sessionStorage, caching unnecessary files, and not implementing a data eviction policy to remove outdated data.
Here are some key considerations:
  • Understand browser storage limitations.
  • Use alternative storage solutions when necessary.
  • Implement robust error handling.

Preventing QuotaExceededError is crucial for maintaining a smooth user experience. By understanding the causes of this error, implementing best practices for storage management, and considering alternative storage solutions, you can build robust web applications that avoid storage-related issues. Remember to monitor storage usage, implement data eviction policies, and use compression to minimize the storage footprint of your application. The W3C Web Storage specification provides further details.

The QuotaExceededError doesn’t have to be a roadblock. By understanding its causes and implementing the strategies we’ve discussed, you can ensure your web application handles storage efficiently and provides a seamless user experience. Don’t let storage limitations hold you back; take control of your data management and build robust, scalable applications. Explore our other articles on web development best practices to further enhance your skills and build even better applications. Let’s build better web experiences together!

Question & Answer :
Using LocalStorage on iPhone with iOS 7 throws this error. I’ve been looking around for a resolvant, but considering I’m not even browsing in private, nothing is relevant.

I don’t understand why localStorage would be disabled by default in iOS 7, but it seems it is? I’ve tested on other websites as well, but with no luck. I even tried testing it using this website: http://arty.name/localstorage.html, but it doesn’t seem like it’s saving anything at all for some weird reason.

Has anyone had the same problem, only they’ve had luck fixing it? Should I switch my storage method?

I tried hard-debugging it by only storing a few lines of information, but to no avail. I used the standard localStorage.setItem() function to save.

This can occur when Safari is in private mode browsing. While in private browsing, local storage is not available at all.

One solution is to warn the user that the app needs non-private mode to work.

UPDATE: This has been fixed in Safari 11, so the behaviour is now aligned with other browsers.