parent
e629584830
commit
5af6ab1045
3 changed files with 44 additions and 0 deletions
frontend
|
@ -5,6 +5,8 @@
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>GPS Tracker</title>
|
<title>GPS Tracker</title>
|
||||||
|
<!-- PWA builder -->
|
||||||
|
<script type="module" src="/js/pwabuilder-sw-register.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|
15
frontend/public/js/pwabuilder-sw-register.js
Normal file
15
frontend/public/js/pwabuilder-sw-register.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// This is the "Background Sync" service worker
|
||||||
|
|
||||||
|
// Add this below content to your HTML page inside a <script type="module"></script> tag, or add the js file to your page at the very top to register service worker
|
||||||
|
// If you get an error about not being able to import, double check that you have type="module" on your <script /> tag
|
||||||
|
|
||||||
|
/*
|
||||||
|
This code uses the pwa-update web component https://github.com/pwa-builder/pwa-update to register your service worker,
|
||||||
|
tell the user when there is an update available and let the user know when your PWA is ready to use offline.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate';
|
||||||
|
|
||||||
|
const el = document.createElement('pwa-update');
|
||||||
|
document.body.appendChild(el);
|
||||||
|
|
27
frontend/public/js/pwabuilder-sw.js
Normal file
27
frontend/public/js/pwabuilder-sw.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// This is the "Offline copy of assets" service worker
|
||||||
|
|
||||||
|
const CACHE = "pwabuilder-offline";
|
||||||
|
const QUEUE_NAME = "bgSyncQueue";
|
||||||
|
|
||||||
|
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
|
||||||
|
|
||||||
|
self.addEventListener("message", (event) => {
|
||||||
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||||
|
self.skipWaiting();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const bgSyncPlugin = new workbox.backgroundSync.BackgroundSyncPlugin(QUEUE_NAME, {
|
||||||
|
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours (specified in minutes)
|
||||||
|
});
|
||||||
|
|
||||||
|
workbox.routing.registerRoute(
|
||||||
|
new RegExp('/*'),
|
||||||
|
new workbox.strategies.StaleWhileRevalidate({
|
||||||
|
cacheName: CACHE,
|
||||||
|
plugins: [
|
||||||
|
bgSyncPlugin
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue