Hi, i have a chat app with service worker enabled for request caching, but i want to maintain some local store techniques like facebook, whatsapp for instant access to user’s chats. What is the best way to do so? Using local storage or anything else for caching?
You might find the following article useful:
In particular you may find the IndexedDB
API quite useful here as chat messages can map quite well into a database
the Cache
API could work too, though it may end up being more work, it’s hard to say
I am already using Cache API with service worker as i said for request caching(messages request), but i want to save more things like uploading a file which isn’t uploaded yet on the server, there is no purpose of updating it in cache API, is it worth shifting from Cache API request caching to IDB? I have tried looking into Facebook and Whatsapp (Whatsapp i think is using IDb but i am not able to decode it completely as deleting the storage retained the chats)
I thought you wanted to cache text messages, didn’t think about files and images
The ugly hacky side of me would say to just stringify it and stick it in localStorage
, though I’ve been bitten by that in the past when I accidentally hit Chrome’s localStorage
security limits by storing too much there temporarily
There’s nothing as far as I can tell stopping you using both types of storage though is there?
Use IndexedDB for storing your failed image uploads, use Cache for request caching, and update an in-memory copy of what the user sees based on those perhaps
Perhaps someone that’s made a similar app to you will come along with better advice