content-index
content-index copied to clipboard
oncontentadded event
Hello. At the moment, if I have a complex service worker that wants to take notice of content being added, I can either
- do that additional work everytime I call
index.add()
- use setInterval() or some such & call
index.getAll()
& diff, checking for new content
Since we have this index, & this index already can tell us when content goes away, it would also be nice to know when content is added. This would be a more normalized path than (1) or (2).
Currently, the contentdelete
event only fires if the deletion was originated by the user.
But like the idea of have generic contentadd
and contentdelete
events. Even though there are workarounds like you mentioned, it could simplify some of the synchronization logic.
@jeffposnick Any thoughts on the matter considering you've been looking into the best way to synchronize content index entries in a web app?
(Summarizing some thoughts from https://twitter.com/jeffposnick/status/1207784110732795910)
The "source of truth" that made the most sense to me was the Cache Storage API (or IDB, if you use that for your offline data). I'm not sure what the right interval for syncing the Cache Storage API state with the Content Indexing API is, but it's been cheap enough that doing it each time my web app starts up hasn't seemed to be a problem.
Listening to contentdelete
and then removing the related Response
s from Cache Storage is the "right" thing to do, in that it would prevent items from reappearing in the UX—in my model, where Cache Storage is the source of truth, the items would get added to the index again once my web app starts up.
I don't actually see a need for a contentadd
event, though, since I'm not aware of a mechanism for a user to specify a URL that they would like to be available offline outside of a web app's normal user interface. If we get to the point where there is some browser end-user interface that supports entering an arbitrary URL and we want a way to signal to the web app that the URL should be cached for offline use, then maybe contentadd
would make sense.