1

I would like to create my first PWA app and I want to use sw-precache. I would like to have push notifications in my app, but I don't see any option to add push notification and notification click listeners via sw-precache generate.

Should I add some sort of concatenate after the files is generated?

Does anyone knows how to do this?

Blejwi
  • 1,005
  • 2
  • 10
  • 25
  • Currently push button on Chrome(version 70) is broken. Installed Canary and Jeff's approach worked for me. Spent couple of hours debugging in Chrome, hopefully this post will save time for others. – Manas Nov 20 '18 at 22:27

1 Answers1

11

You can add in additional logic using the importScripts option in sw-precache.

For example, if you create a push-listener.js file with the following:

self.addEventListener('push', event => {
  // Your code here.
});

You can configure sw-precache to import it:

{
  importScripts: ['path/to/push-listener.js'],
  // Other sw-precache options here.
}
Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167
  • 1
    just to add to Jeff's reply. Caching and push notifications are separate things. So a tool like precache does nothing directly with push notifications. – Chris Love Jun 15 '17 at 14:07
  • Hi. I've added the script and imported it with importScript setting. I can run a console.log in the imported script but any EventListerns like this don't work. Does anyone know why the event listeners do not work? – Ultronn May 26 '18 at 17:53