MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Storage Quotas & Persistence Policies0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
7.1IndexedDB Architecture & Transactions7.2Storing Complex Objects & Blobs in IndexedDB7.3Cache API & Service Worker Storage7.4Storage Quotas & Persistence Policies
HomeTutorialsJavaScript for AdvancedStorage Quotas & Persistence Policies
Custom Events & Event Dispatching

Storage Quotas & Persistence Policies

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

When web applications store hundreds of megabytes of media, offline databases, and application assets via IndexedDB and the Cache API, browsers enforce storage management policies. Understanding Storage Quotas, eviction algorithms, and requesting Persistent Storage ensures your app's offline data is never unexpectedly purged by the browser.


1. Storage Quotas: Best-Effort vs. Persistent

By default, all web storage (IndexedDB, Cache API, LocalStorage) operates in Best-Effort mode:

  • Best-Effort Storage: If device disk space runs critically low, the browser's storage manager automatically evicts (deletes) entire origin storage trees without asking the user, using an LRU (Least Recently Used) policy!
  • Persistent Storage: Data is guaranteed not to be deleted by automatic browser clearing. It can only be cleared if the user explicitly clears browser data.
1Storage Mode:
2 ├── Best-Effort (Default) ──► Low Disk Space? ──► Silently Deleted by Browser!
3 └── Persistent Storage ──► Low Disk Space? ──► PRESERVED! User must manually clear.

2. Inspecting Storage Quota with navigator.storage.estimate()

To monitor available space and consumption in bytes:

1async function checkStorageQuota() {
2 if (navigator.storage && navigator.storage.estimate) {
3 const { quota, usage } = await navigator.storage.estimate();
4 
5 const usageMB = (usage / (1024 * 1024)).toFixed(2);
6 const quotaMB = (quota / (1024 * 1024)).toFixed(2);
7 const percentUsed = ((usage / quota) * 100).toFixed(1);
8 
9 console.log(`Storage: ${usageMB} MB used of ${quotaMB} MB available (${percentUsed}%)`);
10 
11 if (percentUsed > 80) {
12 console.warn('Storage quota above 80%! Prompting user to clear old media.');
13 }
14 }
15}

3. Requesting Persistent Storage: navigator.storage.persist()

To transition your origin from Best-Effort to Persistent storage, request persistence:

1async function requestPersistentStorage() {
2 if (navigator.storage && navigator.storage.persist) {
3 // Check if already persistent
4 const isAlreadyPersistent = await navigator.storage.persisted();
5 console.log('Already persistent:', isAlreadyPersistent);
6 
7 if (!isAlreadyPersistent) {
8 // Request permission from browser/user
9 const isGranted = await navigator.storage.persist();
10 console.log(`Persistent storage granted: ${isGranted}`);
11
12 if (isGranted) {
13 console.log('Data is protected from automatic browser eviction.');
14 } else {
15 console.log('Operating in best-effort storage mode.');
16 }
17 }
18 }
19}

Browser Granting Heuristics:

Browsers (Chrome, Firefox, Safari) may grant persistent storage automatically without a prompt if:

  • The site is installed as a PWA (added to home screen).
  • The user has bookmarked the site.
  • The user has high engagement (frequent visits).
  • Push notification permissions have been granted.

4. Handling Storage Overflows: QuotaExceededError

When attempting to store data beyond the allowed quota, operations throw a QuotaExceededError (DOMException code 22). Always catch this error defensively:

1try {
2 await cache.put(request, largeResponse);
3} catch (error) {
4 if (error.name === 'QuotaExceededError') {
5 console.error('Disk quota exceeded! Purging non-essential caches.');
6 purgeOldestCacheBucket();
7 }
8}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What happens to data stored in "Best-Effort" mode when the client device runs low on disk space?
Question 2
Which method requests the browser to exempt an application from automatic storage eviction?
Question 3
What function calculates current storage usage and maximum quota allocation in bytes?
Question 4
What error is thrown when an IndexedDB or Cache API write exceeds available storage capacity?
Question 5
How can a developer verify whether the current site has already been granted persistent storage?
Next Lesson

Custom Events & Event Dispatching

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Cache API & Service Worker StorageCustom Events & Event Dispatching

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext