Service worker precache
Yarn upgrades / cleanup
This commit is contained in:
@ -1,22 +1,14 @@
|
||||
/// <reference lib="webworker" />
|
||||
declare const self: ServiceWorkerGlobalScope;
|
||||
declare const self: ServiceWorkerGlobalScope & {
|
||||
__WB_MANIFEST: (string | PrecacheEntry)[]
|
||||
};
|
||||
|
||||
import { clientsClaim } from "workbox-core";
|
||||
import { registerRoute } from "workbox-routing";
|
||||
import { CacheFirst } from "workbox-strategies";
|
||||
import {PrecacheEntry, precacheAndRoute} from 'workbox-precaching';
|
||||
|
||||
precacheAndRoute(self.__WB_MANIFEST);
|
||||
clientsClaim();
|
||||
|
||||
const staticTypes = ["image", "video", "audio", "script", "style", "font"];
|
||||
const paths = ["/"];
|
||||
registerRoute(
|
||||
({ request, url }) =>
|
||||
url.origin === self.location.origin && (staticTypes.includes(request.destination) || paths.includes(url.pathname)),
|
||||
new CacheFirst({
|
||||
cacheName: "static-content",
|
||||
})
|
||||
);
|
||||
|
||||
self.addEventListener("message", event => {
|
||||
if (event.data && event.data.type === "SKIP_WAITING") {
|
||||
self.skipWaiting();
|
||||
|
Reference in New Issue
Block a user