When to deploy service worker?

I have an idea about service workers in websites.

I have service worker that caches ALL web app files from CSS, JS to ALL the used images once activated, that is the purpose of service worker, right. It’s like an app installation (once you register).

However, I do not see any point of installing it on every new user visit, in case the user never/ever visits any other page on my website, and the user never/ever returns to my website or registers an account, right? This takes a lot of extra bandwidth to cache ALL the website files the user may not need, because the user visits only first home page and leaves.

What’s the idea behind of deploying service worker all the time, like Twitter does, can anyone explain?

Thank you!

Well no, caching all assets is not what a service worker is supposed to do; there’s only limited storage space available to begin with, so you have to choose a proper caching strategy. And it’s not exactly like an app installation, it’s called a progressive web app; a common pattern for caching is the app shell model, which would only cache the fundamental UI, not actual content images etc. (or not for long at any rate).

2 Likes

I tested in Chrome, that I can use two different service workers for the same scope. The “light” one at start and another one for the member area.

Thanks Everyone

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.