3 ms·
You could very easily handle storing to localstorage or indexeddb using stores. However, in larger projects that can become error prone and increase complexity
by doodlesdev 4y ago
You could very easily handle storing to localstorage or indexeddb using stores. However, in larger projects that can become error prone and increase complexity (unnecessarily).
To simplify this workflow you could use something like https://github.com/andsala/svelte-persistent-store https://github.com/andsala/svelte-persistent-store
Note that repo is basically 50 lines of code to automate this stuff, which is pretty remarkable. However this still won't handle cache invalidation or syncing.
https://sveltequery.vercel.app/ https://sveltequery.vercel.app/ should handle most use cases. This is very similar to React Query (since it's from the same devs at https://tanstack.com/ https://tanstack.com/).
For handling the service workers stuff for (what I assume would be a PWA) I'd just use the Vite PWA plugin which uses workbox. That's if I need a service worker at all, if I don't I'd just set the manifest and be done with it.
An alternative depending on the needs of the specific project is to just fallback on something like the Firebase or Supabase SDK which handle offline mutations and syncing for you, for simpler projects these work incredibly well.