Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Storage for the WEB

Storage for the WEB

Talking about storage of Web Based Application

Hyperjump Tech

April 16, 2024
Tweet

More Decks by Hyperjump Tech

Other Decks in Programming

Transcript

  1. What should I use? ▪ For the network resources necessary

    to load your app and file-based content, use the Cache Storage API ▪ For other data, use IndexedDB
  2. LocalStorage should be avoided because it is synchronous and will

    block the main thread. It is limited to about 5MB and can contain only strings. LocalStorage is not accessible from web workers or service workers.
  3. SessionStorage is tab specific, and scoped to the lifetime of

    the tab. It may be useful for storing small amounts of session specific information It should be used with caution because it is synchronous and will block the main thread. It is limited to about 5MB and can contain only strings. Because it is tab specific, it is not accessible from web workers or service workers.
  4. Cookies ▪ have their uses, but should not be used

    for storage. ▪ Cookies are sent with every HTTP request, so storing anything more than a small amount of data will significantly increase the size of every web request. ▪ They are synchronous, and are not accessible from web workers. ▪ Like LocalStorage and SessionStorage, cookies are limited to only strings.
  5. WebSQL ▪ Was a wrapper of sqlite for web ▪

    should not be used, and existing usage should be migrated to IndexedDB. ▪ Support has been removed from almost all major browsers. ▪ The W3C stopped maintaining the Web SQL spec in 2010, with no plans to further updates planned
  6. IndexedDB ▪ asynchronous, and will not block the main thread

    ▪ They're accessible from the window object, web workers, and service workers, making it easy to use them anywhere in your code
  7. How much can I store? In short, a lot, at

    least a couple of hundred megabytes, and potentially hundreds of gigabytes or more
  8. ▪ Chrome allows the browser to use up to 80%

    of total disk space ▪ Internet Explorer 10 and later can store up to 250MB ▪ Firefox allows the browser to use up to 50% of free disk space ▪ Safari (both desktop and mobile) appears to allow about 1GB.
  9. How does eviction work? Best Effort ▪ Chromium-based browsers ->

    clearing all site data from the least recently used origin first, then the next, until the browser is no longer over the limit. ▪ Internet Explorer 10+ -> will not evict data but will prevent the origin from writing any more ▪ Firefox -> clearing all site data from the least recently used origin first, then the next, until the browser is no longer over the limit. ▪ Safari previously did not evict data, but recently implemented a new seven- day cap on all writable storage. This means Safari will evict all content from the cache after seven days of Safari use if the user does not interact with the site
  10. Conclusion Gone are the days of limited storage and prompting

    the user to store more and more data. Sites can store effectively all of the resources and data they need to run. Using the StorageManager API you can determine how much is available to you, and how much you've used. And with persistent storage, unless the user removes it, you can protect it from eviction.