Skip to content

Commit affbbaa

Browse files
committed
old service worker added
1 parent 8f0b54b commit affbbaa

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

src/service-worker.ts

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { precacheAndRoute } from 'workbox-precaching'
2-
import { NavigationRoute, registerRoute, Route } from 'workbox-routing'
3-
import * as navigationPreload from 'workbox-navigation-preload'
4-
import { NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
1+
// import { precacheAndRoute } from 'workbox-precaching'
2+
// import { NavigationRoute, registerRoute, Route } from 'workbox-routing'
3+
// import * as navigationPreload from 'workbox-navigation-preload'
4+
// import { NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies'
5+
// import { clientsClaim } from 'workbox-core'
6+
7+
import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching'
8+
import { NavigationRoute, registerRoute } from 'workbox-routing'
59
import { clientsClaim } from 'workbox-core'
610

711
declare let self: ServiceWorkerGlobalScope
@@ -13,38 +17,13 @@ self.addEventListener('message', (event) => {
1317
}
1418
})
1519

16-
clientsClaim()
17-
18-
// Precache the manifest
20+
// self.__WB_MANIFEST is default injection point
1921
precacheAndRoute(self.__WB_MANIFEST)
2022

21-
// Enable navigation preload
22-
navigationPreload.enable()
23-
24-
// Create a new navigation route that uses the Network-first, falling back to
25-
// cache strategy for navigation requests with its own cache. This route will be
26-
// handled by navigation preload. The NetworkOnly strategy will work as well.
27-
const navigationRoute = new NavigationRoute(
28-
new NetworkFirst({
29-
cacheName: 'navigations',
30-
}),
31-
)
23+
// clean old assets
24+
cleanupOutdatedCaches()
3225

33-
// Register the navigation route
34-
registerRoute(navigationRoute)
35-
36-
// Create a route for image, script, or style requests that use a
37-
// stale-while-revalidate strategy. This route will be unaffected
38-
// by navigation preload.
39-
const staticAssetsRoute = new Route(
40-
({ request }) => {
41-
return ['image', 'script', 'style'].includes(request.destination)
42-
},
43-
new StaleWhileRevalidate({
44-
cacheName: 'static-assets',
45-
}),
46-
)
47-
48-
// Register the route handling static assets
49-
registerRoute(staticAssetsRoute)
26+
// to allow work offline
27+
registerRoute(new NavigationRoute(createHandlerBoundToURL('index.html')))
5028

29+
clientsClaim()

0 commit comments

Comments
 (0)