Skip to content

Service Worker Example: Template for apps that enable service-worker builder to expose Service Worker implementations

Notifications You must be signed in to change notification settings

sergio773/service-worker-example

 
 

Repository files navigation

Service Worker Example

Service Workers (SWs) are a poweful tool to handle network requests separate from a web page, as scripts running in the background. They are well known to handle push notifications and background syncronization.

With service-worker builder, we can allow an app to expose its own implementation of a Service Worker, enabling VTEX stores to use such Service Worker into their scope.

Service Workers allow us to introduce 6 different event handlers, which can be implemented inside the service-workers/ folder:

  1. activateactivate.js
  2. fetchfetch.js
  3. installinstall.js
  4. messagemessage.js
  5. pushpush.js
  6. syncsync.js

Whatever is outside those 6 files, should be implemented in header.js. The implementation result in the VTEX store DevTools should be as follows:

image

Each function can be tested according to the behavior of each event handler. When triggering such event handler, the function body will be executed as follows:

image

An example is provided in this app for exploration purposes.

About

Service Worker Example: Template for apps that enable service-worker builder to expose Service Worker implementations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%