Vadim Dalecky2 months ago

Browser on-disk storage APIs:

  • document.cookie — a “cookie” is the oldest persistence mechanism, by simply updating the document.cookie property the browser will synchronously update the value.

  • localStorage — synchronously stores a key-value pair on the disk, historically every write to disk used to be blocking, now browsers seem to optimize this.

  • WebSQL — a deprecated SQL standard for the browser.

  • IndexedDB — the current “database API” of the browsers. It used to have asynchronous and synchronous variants, now the synchronous variant is deprecated and works only in worker threads.

  • CacheStorage — key/value storage of service workers.

  • OPFS — a virtual file system implemented as FSA. It exposes only asynchronous API from the main threads, but synchronous reads and writes are available from the worker threads. Using the Atomic.wait trick, it is possible to achieve synchronous reads and writes from the main thread, too.

  • FSA (File System Access) — File System Access, it is implemented using the FSA (File System API), just like, OPFS, but it gives access to real user files on their device. Requires user permission to access a file or a folder, however, the permission object can be stored in IndexDB, which is accessible after browser reload.