vi_gne_sh
vi_gne_sh

Reputation: 59

Can a service worker update the cache without an open tab?

I want to give the user a speed feel when he accesses my website. If I cache the initial page in service worker, then I can achieve it. But I am having the following doubts.

Upvotes: 1

Views: 121

Answers (1)

NOtherDev
NOtherDev

Reputation: 9672

1) Not in a simple way - your Service Worker is suspended until something wakes it up, for example the user opening your app. Or the push message. So you might run your cache update flow in a push message handler and send the push to all subscribed users whenever the update should happen. But you have to be aware that there are limitations of how many pushes can the app receive and/or how long the handler can run.

"Normally" this is done when the new Service Worker version is installing and requires reload (or manual handling) to take effect.

2) Yes, the general storage limit applies. It is OS-specific and you can query for the estimate with Quota Estimation API (Chrome only by now).

Upvotes: 2

Related Questions