thebigk's avatar
Level 13

Workbox and Push Notification Integration

I'm currently building a progressive web app with Workbox. It's got almost everything working; except that I can't figure out how to integrate push notification.

Here's what I have in my webpack.mix.js

const workboxPlugin = require('workbox-webpack-plugin');
mix.webpackConfig({
        plugins: [
            new workboxPlugin.InjectManifest({
                swSrc: 'public/sw-offline.js', // more control over the caching
                swDest: 'sw.js', // the service-worker file name
                importsDirectory: 'sw-assets' // have a dedicated folder for sw files
            })
        ]
});

In the sw-offline.js, I define the asset caching policies -

workbox.skipWaiting();
workbox.clientsClaim();
// static
workbox.routing.registerRoute(
    new RegExp('.(?:js|css|ico)$'),
    workbox.strategies.networkFirst({
        cacheName: 'static'
    }),
);

Where and how exactly should I integrate the Push API? It's been several hours since I'm investigating this - and there seems to be inadequate information in Google documentation.

Would really appreciate if someone could guide. Thank you in advance.

0 likes
3 replies
thebigk's avatar
Level 13

Thank you @braunson - does it offer a single solution for messaging on PWAs across iOS and Android platform?

Braunson's avatar

@THEBIGK - Not entirely sure about (native) iOS or Andorid push notifications but it does support Mobile Safari/Chrome web push notifications.

Please or to participate in this conversation.