Storage: Storage size limits

Through the Storage API you can store more data than you would be able with cookies.

The current limits on desktop seem to be 10MB across browsers for both localStorage and sessionStorage, with 5MB each, per origin (per single website).

After this limit is reached, calling setItem will raise a QuotaExceededError exception, and you can intercept that using a try/catch:

try {
  localStorage.setItem('key', 'value')
} catch (e) {
  if (
    [
      'QuotaExceededError', 
      'NS_ERROR_DOM_QUOTA_REACHED' /* Firefox */
    ].includes(
      e.name
    )
  ) {
    // handle quota limit exceeded error
    console.error('Quota exceeded')
  } else {
    // another kind of exception
    throw e
  }
}

Lessons in this unit:

0: Introduction
1: Session vs local storage
2: Setting an item
3: Getting an item value
4: Removing an item
5: Clearing storage
6: ▶︎ Storage size limits
Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. Launching May 21, 2024. Join the waiting list!