PWA on IOS
https://www.netguru.com/codestories/pwa-on-ios
Sample service worker
I am trying to implement a serviceworker with workbox. Everything is being cached online, but when I am going offline, I am getting "ERR_INTERNET_DISCONNECTED" error message. Also my precache and runtimecache is gone when I go offline.
When I write my own fetch method (without using the workbox routing methods), the serviceworker is working offline. And as far as I understood, fetching requests is handled by the handler in the routing methods, or am I wrong? So what am I missing to get my app working when in offline mode?
Here is my serviceworker source file (the precache files are being added during the build process):
importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"
);
workbox.precaching.precacheAndRoute([]);
self.addEventListener("message", event => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
const bgSyncPlugin = new workbox.backgroundSync.Plugin("myQueueName", {
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours (specified in minutes)
});
workbox.routing.registerRoute(
/\/api\/.*\/*.json/,
new workbox.strategies.NetworkOnly({
cacheName: "apiCallCache",
plugins: [bgSyncPlugin]
}),
"POST"
);
workbox.routing.registerRoute(
//match
/\.(?:png|jpg|jpeg|svg|gif|css|js)$/,
//handler
new workbox.strategies.StaleWhileRevalidate({
cacheName: "runtimeCache"
})
);
use workbox locally
importScripts('/third_party/workbox/workbox-sw.js');
workbox.setConfig({
modulePathPrefix: '/third_party/workbox/'
});