Open dfabulich opened 6 months ago
Oh, yes I am already planning to switch to IndexedDB in the future! But making the whole system async is a massive task. See #11 for a checklist. I'm getting there though, I'm going to add my rewrite of GlkApi into Parchment for testing hopefully this week.
Something I learned recently that may be of interest to you.
localStorage
is limited to 5MB, but IndexedDB has a much larger storage limit.https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria
The biggest gotcha here is that
localStorage
is synchronous, but IndexedDB is asynchronous.The second biggest gotcha is that
IndexedDB
is a much more complicated API. You might enjoy this library https://github.com/jakearchibald/idb-keyval which provides a Promisified wrapper around IDB.The third biggest gotcha has to do with sharing IndexedDB between multiple games, especially in the single-file HTML mode, where all
file://
URLs are the same origin.In ChoiceScript, which generates offline-enabled HTML files, I handled this by using a different database for each game. https://github.com/jakearchibald/idb-keyval/blob/main/custom-stores.md (Note that I don't recommend sharing one database and creating multiple object stores per database, because the only time you're allowed to create an object store is when creating or "upgrading" the database to a higher version number.) I used the IFID as the unique identifier for each game. Seems to be working OK.