DEV Community

Discussion on: The thing about service workers...

Collapse
 
dar5hak profile image
Darshak Parikh

While I don't have much experience in this, I think a conservative approach would work here:

  1. Release v1.0 without any service worker. (Honestly, we haven't reached a time when everyday people complain about the lack of one.)
  2. Observe the rate at which changes come. This is a curve that flattens over time.
  3. Identify the resources which make good candidates to cache. These are things that you can afford to have old versions of, like icons, fonts and non-critical styles.
  4. Write a service worker to cache only these resources and release it. Do display the refresh prompts to users. This stage is meant to test the service worker itself once your core functionality is relatively stable.
  5. Once you know that your service worker is robust enough to handle updates smoothly, add more resources to cache.
  6. Iterate.
Collapse
 
sebastijandumancic profile image
Sebastijan Dumancic

While I agree with your process, caching static assets is solved years ago with server-side caching and cache busting works flawlessly for serving new content when it's available without falling back to old ones first. The issue with offline support for SW is that it's all or nothing, and not caching specific assets. That should be handled by the server, not the browser, either way. Let me know if I'm understanding something wrong about SW config :) Thanks for the comment!

Collapse
 
dar5hak profile image
Darshak Parikh • Edited

Caching using headers is indeed a breeze, but it falls short in two scenarios:

  • When a user has zero internet connectivity, the site won't load unless every resource is cached. (Not tested, but I'm fairly sure.)
  • You cannot control cache headers when serving from a static host like GitHub Pages or Surge.

Service workers offer a lower-level caching mechanism that can bypass these limitations.

That said, if you can control your headers and don't plan on offline access (but are caching for perf improvement), headers are the way to go.