serwist 9.0.12 → 10.0.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Serwist.d.ts +74 -52
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/chunks/resultingClientExists.js +426 -2
- package/dist/{legacy/utils → controllers/PrecacheController}/PrecacheCacheKeyPlugin.d.ts +4 -4
- package/dist/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/{legacy → controllers/PrecacheController}/PrecacheController.d.ts +73 -64
- package/dist/controllers/PrecacheController/PrecacheController.d.ts.map +1 -0
- package/dist/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts +14 -0
- package/dist/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/{PrecacheRoute.d.ts → controllers/PrecacheController/PrecacheRoute.d.ts} +4 -5
- package/dist/controllers/PrecacheController/PrecacheRoute.d.ts.map +1 -0
- package/dist/{lib/strategies → controllers/PrecacheController}/PrecacheStrategy.d.ts +6 -6
- package/dist/controllers/PrecacheController/PrecacheStrategy.d.ts.map +1 -0
- package/dist/controllers/PrecacheController/parsePrecacheOptions.d.ts +25 -0
- package/dist/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +1 -0
- package/dist/controllers/RuntimeCacheController.d.ts +65 -0
- package/dist/controllers/RuntimeCacheController.d.ts.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.js +25 -3
- package/dist/index.js +1868 -211
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts +2 -2
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts +2 -2
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -1
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts +3 -3
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -1
- package/dist/lib/expiration/ExpirationPlugin.d.ts +2 -2
- package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +7 -7
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -1
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts +3 -3
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -1
- package/dist/lib/strategies/Strategy.d.ts +3 -3
- package/dist/lib/strategies/Strategy.d.ts.map +1 -1
- package/dist/lib/strategies/StrategyHandler.d.ts +4 -4
- package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +2 -2
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
- package/dist/types.d.ts +16 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/pluginUtils.d.ts +2 -2
- package/dist/utils/pluginUtils.d.ts.map +1 -1
- package/package.json +5 -12
- package/src/Serwist.ts +157 -262
- package/src/{legacy/utils → controllers/PrecacheController}/PrecacheCacheKeyPlugin.ts +5 -6
- package/src/{legacy → controllers/PrecacheController}/PrecacheController.ts +143 -155
- package/src/{utils → controllers/PrecacheController}/PrecacheInstallReportPlugin.ts +5 -5
- package/src/{PrecacheRoute.ts → controllers/PrecacheController/PrecacheRoute.ts} +11 -12
- package/src/{lib/strategies → controllers/PrecacheController}/PrecacheStrategy.ts +7 -7
- package/src/controllers/PrecacheController/parsePrecacheOptions.ts +46 -0
- package/src/controllers/RuntimeCacheController.ts +119 -0
- package/src/index.ts +5 -2
- package/src/lib/backgroundSync/BackgroundSyncPlugin.ts +2 -2
- package/src/lib/broadcastUpdate/BroadcastUpdatePlugin.ts +2 -2
- package/src/lib/cacheableResponse/CacheableResponsePlugin.ts +3 -3
- package/src/lib/expiration/ExpirationPlugin.ts +2 -2
- package/src/lib/precaching/PrecacheFallbackPlugin.ts +10 -10
- package/src/lib/rangeRequests/RangeRequestsPlugin.ts +3 -3
- package/src/lib/strategies/Strategy.ts +3 -3
- package/src/lib/strategies/StrategyHandler.ts +9 -9
- package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +2 -2
- package/src/types.ts +24 -67
- package/src/utils/pluginUtils.ts +2 -2
- package/dist/PrecacheRoute.d.ts.map +0 -1
- package/dist/chunks/printInstallDetails.js +0 -1601
- package/dist/chunks/waitUntil.js +0 -449
- package/dist/index.legacy.d.ts +0 -28
- package/dist/index.legacy.d.ts.map +0 -1
- package/dist/index.legacy.js +0 -790
- package/dist/legacy/PrecacheController.d.ts.map +0 -1
- package/dist/legacy/PrecacheFallbackPlugin.d.ts +0 -61
- package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/legacy/PrecacheRoute.d.ts +0 -19
- package/dist/legacy/PrecacheRoute.d.ts.map +0 -1
- package/dist/legacy/Router.d.ts +0 -151
- package/dist/legacy/Router.d.ts.map +0 -1
- package/dist/legacy/addPlugins.d.ts +0 -9
- package/dist/legacy/addPlugins.d.ts.map +0 -1
- package/dist/legacy/addRoute.d.ts +0 -14
- package/dist/legacy/addRoute.d.ts.map +0 -1
- package/dist/legacy/constants.d.ts +0 -10
- package/dist/legacy/constants.d.ts.map +0 -1
- package/dist/legacy/createHandlerBoundToURL.d.ts +0 -17
- package/dist/legacy/createHandlerBoundToURL.d.ts.map +0 -1
- package/dist/legacy/fallbacks.d.ts +0 -59
- package/dist/legacy/fallbacks.d.ts.map +0 -1
- package/dist/legacy/getCacheKeyForURL.d.ts +0 -20
- package/dist/legacy/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/legacy/handlePrecaching.d.ts +0 -54
- package/dist/legacy/handlePrecaching.d.ts.map +0 -1
- package/dist/legacy/initializeGoogleAnalytics.d.ts +0 -38
- package/dist/legacy/initializeGoogleAnalytics.d.ts.map +0 -1
- package/dist/legacy/installSerwist.d.ts +0 -81
- package/dist/legacy/installSerwist.d.ts.map +0 -1
- package/dist/legacy/matchPrecache.d.ts +0 -15
- package/dist/legacy/matchPrecache.d.ts.map +0 -1
- package/dist/legacy/precache.d.ts +0 -20
- package/dist/legacy/precache.d.ts.map +0 -1
- package/dist/legacy/precacheAndRoute.d.ts +0 -14
- package/dist/legacy/precacheAndRoute.d.ts.map +0 -1
- package/dist/legacy/registerRoute.d.ts +0 -16
- package/dist/legacy/registerRoute.d.ts.map +0 -1
- package/dist/legacy/registerRuntimeCaching.d.ts +0 -11
- package/dist/legacy/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/legacy/setCatchHandler.d.ts +0 -10
- package/dist/legacy/setCatchHandler.d.ts.map +0 -1
- package/dist/legacy/setDefaultHandler.d.ts +0 -13
- package/dist/legacy/setDefaultHandler.d.ts.map +0 -1
- package/dist/legacy/singletonPrecacheController.d.ts +0 -34
- package/dist/legacy/singletonPrecacheController.d.ts.map +0 -1
- package/dist/legacy/singletonRouter.d.ts +0 -41
- package/dist/legacy/singletonRouter.d.ts.map +0 -1
- package/dist/legacy/unregisterRoute.d.ts +0 -9
- package/dist/legacy/unregisterRoute.d.ts.map +0 -1
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/legacy/utils/getCacheKeyForURL.d.ts +0 -14
- package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/lib/strategies/PrecacheStrategy.d.ts.map +0 -1
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/utils/PrecacheInstallReportPlugin.d.ts +0 -14
- package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/utils/parsePrecacheOptions.d.ts +0 -26
- package/dist/utils/parsePrecacheOptions.d.ts.map +0 -1
- package/src/index.legacy.ts +0 -62
- package/src/legacy/PrecacheFallbackPlugin.ts +0 -92
- package/src/legacy/PrecacheRoute.ts +0 -48
- package/src/legacy/Router.ts +0 -484
- package/src/legacy/addPlugins.ts +0 -21
- package/src/legacy/addRoute.ts +0 -27
- package/src/legacy/constants.ts +0 -22
- package/src/legacy/createHandlerBoundToURL.ts +0 -30
- package/src/legacy/fallbacks.ts +0 -94
- package/src/legacy/getCacheKeyForURL.ts +0 -32
- package/src/legacy/handlePrecaching.ts +0 -86
- package/src/legacy/initializeGoogleAnalytics.ts +0 -218
- package/src/legacy/installSerwist.ts +0 -170
- package/src/legacy/matchPrecache.ts +0 -27
- package/src/legacy/precache.ts +0 -33
- package/src/legacy/precacheAndRoute.ts +0 -27
- package/src/legacy/registerRoute.ts +0 -28
- package/src/legacy/registerRuntimeCaching.ts +0 -17
- package/src/legacy/setCatchHandler.ts +0 -21
- package/src/legacy/setDefaultHandler.ts +0 -24
- package/src/legacy/singletonPrecacheController.ts +0 -53
- package/src/legacy/singletonRouter.ts +0 -70
- package/src/legacy/unregisterRoute.ts +0 -13
- package/src/legacy/utils/getCacheKeyForURL.ts +0 -36
- package/src/utils/PrecacheCacheKeyPlugin.ts +0 -33
- package/src/utils/parsePrecacheOptions.ts +0 -47
package/dist/index.legacy.js
DELETED
|
@@ -1,790 +0,0 @@
|
|
|
1
|
-
import { P as PrecacheStrategy, c as createCacheKey, h as PrecacheInstallReportPlugin, i as parallel, j as printInstallDetails, k as printCleanupDetails, R as Route, g as generateURLVariations, f as defaultMethod, n as normalizeHandler, p as parseRoute, S as Strategy, b as NavigationRoute, B as BackgroundSyncPlugin, N as NetworkFirst, a as NetworkOnly, e as enableNavigationPreload, s as setCacheNameDetails, d as disableDevLogs } from './chunks/printInstallDetails.js';
|
|
2
|
-
import { c as cacheNames, f as finalAssertExports, S as SerwistError, l as logger, w as waitUntil, g as getFriendlyURL, b as cleanupOutdatedCaches, a as clientsClaim } from './chunks/waitUntil.js';
|
|
3
|
-
import 'idb';
|
|
4
|
-
|
|
5
|
-
class PrecacheCacheKeyPlugin {
|
|
6
|
-
_precacheController;
|
|
7
|
-
constructor({ precacheController }){
|
|
8
|
-
this._precacheController = precacheController;
|
|
9
|
-
}
|
|
10
|
-
cacheKeyWillBeUsed = async ({ request, params })=>{
|
|
11
|
-
const cacheKey = params?.cacheKey || this._precacheController.getCacheKeyForURL(request.url);
|
|
12
|
-
return cacheKey ? new Request(cacheKey, {
|
|
13
|
-
headers: request.headers
|
|
14
|
-
}) : request;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class PrecacheController {
|
|
19
|
-
_installAndActiveListenersAdded;
|
|
20
|
-
_concurrentPrecaching;
|
|
21
|
-
_strategy;
|
|
22
|
-
_urlsToCacheKeys = new Map();
|
|
23
|
-
_urlsToCacheModes = new Map();
|
|
24
|
-
_cacheKeysToIntegrities = new Map();
|
|
25
|
-
constructor({ cacheName, plugins = [], fallbackToNetwork = true, concurrentPrecaching = 1 } = {}){
|
|
26
|
-
this._concurrentPrecaching = concurrentPrecaching;
|
|
27
|
-
this._strategy = new PrecacheStrategy({
|
|
28
|
-
cacheName: cacheNames.getPrecacheName(cacheName),
|
|
29
|
-
plugins: [
|
|
30
|
-
...plugins,
|
|
31
|
-
new PrecacheCacheKeyPlugin({
|
|
32
|
-
precacheController: this
|
|
33
|
-
})
|
|
34
|
-
],
|
|
35
|
-
fallbackToNetwork
|
|
36
|
-
});
|
|
37
|
-
this.install = this.install.bind(this);
|
|
38
|
-
this.activate = this.activate.bind(this);
|
|
39
|
-
}
|
|
40
|
-
get strategy() {
|
|
41
|
-
return this._strategy;
|
|
42
|
-
}
|
|
43
|
-
precache(entries) {
|
|
44
|
-
this.addToCacheList(entries);
|
|
45
|
-
if (!this._installAndActiveListenersAdded) {
|
|
46
|
-
self.addEventListener("install", this.install);
|
|
47
|
-
self.addEventListener("activate", this.activate);
|
|
48
|
-
this._installAndActiveListenersAdded = true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
addToCacheList(entries) {
|
|
52
|
-
if (process.env.NODE_ENV !== "production") {
|
|
53
|
-
finalAssertExports.isArray(entries, {
|
|
54
|
-
moduleName: "serwist/legacy",
|
|
55
|
-
className: "PrecacheController",
|
|
56
|
-
funcName: "addToCacheList",
|
|
57
|
-
paramName: "entries"
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const urlsToWarnAbout = [];
|
|
61
|
-
for (const entry of entries){
|
|
62
|
-
if (typeof entry === "string") {
|
|
63
|
-
urlsToWarnAbout.push(entry);
|
|
64
|
-
} else if (entry && !entry.integrity && entry.revision === undefined) {
|
|
65
|
-
urlsToWarnAbout.push(entry.url);
|
|
66
|
-
}
|
|
67
|
-
const { cacheKey, url } = createCacheKey(entry);
|
|
68
|
-
const cacheMode = typeof entry !== "string" && entry.revision ? "reload" : "default";
|
|
69
|
-
if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) {
|
|
70
|
-
throw new SerwistError("add-to-cache-list-conflicting-entries", {
|
|
71
|
-
firstEntry: this._urlsToCacheKeys.get(url),
|
|
72
|
-
secondEntry: cacheKey
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (typeof entry !== "string" && entry.integrity) {
|
|
76
|
-
if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) {
|
|
77
|
-
throw new SerwistError("add-to-cache-list-conflicting-integrities", {
|
|
78
|
-
url
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
this._cacheKeysToIntegrities.set(cacheKey, entry.integrity);
|
|
82
|
-
}
|
|
83
|
-
this._urlsToCacheKeys.set(url, cacheKey);
|
|
84
|
-
this._urlsToCacheModes.set(url, cacheMode);
|
|
85
|
-
if (urlsToWarnAbout.length > 0) {
|
|
86
|
-
const warningMessage = `Serwist is precaching URLs without revision info: ${urlsToWarnAbout.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;
|
|
87
|
-
if (process.env.NODE_ENV === "production") {
|
|
88
|
-
console.warn(warningMessage);
|
|
89
|
-
} else {
|
|
90
|
-
logger.warn(warningMessage);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
install(event) {
|
|
96
|
-
return waitUntil(event, async ()=>{
|
|
97
|
-
const installReportPlugin = new PrecacheInstallReportPlugin();
|
|
98
|
-
this.strategy.plugins.push(installReportPlugin);
|
|
99
|
-
await parallel(this._concurrentPrecaching, Array.from(this._urlsToCacheKeys.entries()), async ([url, cacheKey])=>{
|
|
100
|
-
const integrity = this._cacheKeysToIntegrities.get(cacheKey);
|
|
101
|
-
const cacheMode = this._urlsToCacheModes.get(url);
|
|
102
|
-
const request = new Request(url, {
|
|
103
|
-
integrity,
|
|
104
|
-
cache: cacheMode,
|
|
105
|
-
credentials: "same-origin"
|
|
106
|
-
});
|
|
107
|
-
await Promise.all(this.strategy.handleAll({
|
|
108
|
-
event,
|
|
109
|
-
request,
|
|
110
|
-
url: new URL(request.url),
|
|
111
|
-
params: {
|
|
112
|
-
cacheKey
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
});
|
|
116
|
-
const { updatedURLs, notUpdatedURLs } = installReportPlugin;
|
|
117
|
-
if (process.env.NODE_ENV !== "production") {
|
|
118
|
-
printInstallDetails(updatedURLs, notUpdatedURLs);
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
updatedURLs,
|
|
122
|
-
notUpdatedURLs
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
activate(event) {
|
|
127
|
-
return waitUntil(event, async ()=>{
|
|
128
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
129
|
-
const currentlyCachedRequests = await cache.keys();
|
|
130
|
-
const expectedCacheKeys = new Set(this._urlsToCacheKeys.values());
|
|
131
|
-
const deletedCacheRequests = [];
|
|
132
|
-
for (const request of currentlyCachedRequests){
|
|
133
|
-
if (!expectedCacheKeys.has(request.url)) {
|
|
134
|
-
await cache.delete(request);
|
|
135
|
-
deletedCacheRequests.push(request.url);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (process.env.NODE_ENV !== "production") {
|
|
139
|
-
printCleanupDetails(deletedCacheRequests);
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
deletedCacheRequests
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
getURLsToCacheKeys() {
|
|
147
|
-
return this._urlsToCacheKeys;
|
|
148
|
-
}
|
|
149
|
-
getCachedURLs() {
|
|
150
|
-
return [
|
|
151
|
-
...this._urlsToCacheKeys.keys()
|
|
152
|
-
];
|
|
153
|
-
}
|
|
154
|
-
getCacheKeyForURL(url) {
|
|
155
|
-
const urlObject = new URL(url, location.href);
|
|
156
|
-
return this._urlsToCacheKeys.get(urlObject.href);
|
|
157
|
-
}
|
|
158
|
-
getIntegrityForCacheKey(cacheKey) {
|
|
159
|
-
return this._cacheKeysToIntegrities.get(cacheKey);
|
|
160
|
-
}
|
|
161
|
-
async matchPrecache(request) {
|
|
162
|
-
const url = request instanceof Request ? request.url : request;
|
|
163
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
164
|
-
if (cacheKey) {
|
|
165
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
166
|
-
return cache.match(cacheKey);
|
|
167
|
-
}
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
createHandlerBoundToURL(url) {
|
|
171
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
172
|
-
if (!cacheKey) {
|
|
173
|
-
throw new SerwistError("non-precached-url", {
|
|
174
|
-
url
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
return (options)=>{
|
|
178
|
-
options.request = new Request(url);
|
|
179
|
-
options.params = {
|
|
180
|
-
cacheKey,
|
|
181
|
-
...options.params
|
|
182
|
-
};
|
|
183
|
-
return this.strategy.handle(options);
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
let defaultPrecacheController = undefined;
|
|
189
|
-
const getSingletonPrecacheController = ()=>{
|
|
190
|
-
if (!defaultPrecacheController) {
|
|
191
|
-
defaultPrecacheController = new PrecacheController();
|
|
192
|
-
}
|
|
193
|
-
return defaultPrecacheController;
|
|
194
|
-
};
|
|
195
|
-
const setSingletonPrecacheController = (precacheController)=>{
|
|
196
|
-
defaultPrecacheController = precacheController;
|
|
197
|
-
return defaultPrecacheController;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
class PrecacheFallbackPlugin {
|
|
201
|
-
_fallbackUrls;
|
|
202
|
-
_precacheController;
|
|
203
|
-
constructor({ fallbackUrls, precacheController }){
|
|
204
|
-
this._fallbackUrls = fallbackUrls;
|
|
205
|
-
this._precacheController = precacheController || getSingletonPrecacheController();
|
|
206
|
-
}
|
|
207
|
-
async handlerDidError(param) {
|
|
208
|
-
for (const fallback of this._fallbackUrls){
|
|
209
|
-
if (typeof fallback === "string") {
|
|
210
|
-
const fallbackResponse = await this._precacheController.matchPrecache(fallback);
|
|
211
|
-
if (fallbackResponse !== undefined) {
|
|
212
|
-
return fallbackResponse;
|
|
213
|
-
}
|
|
214
|
-
} else if (fallback.matcher(param)) {
|
|
215
|
-
const fallbackResponse = await this._precacheController.matchPrecache(fallback.url);
|
|
216
|
-
if (fallbackResponse !== undefined) {
|
|
217
|
-
return fallbackResponse;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
class PrecacheRoute extends Route {
|
|
226
|
-
constructor(precacheController, options){
|
|
227
|
-
const match = ({ request })=>{
|
|
228
|
-
const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
|
|
229
|
-
for (const possibleURL of generateURLVariations(request.url, options)){
|
|
230
|
-
const cacheKey = urlsToCacheKeys.get(possibleURL);
|
|
231
|
-
if (cacheKey) {
|
|
232
|
-
const integrity = precacheController.getIntegrityForCacheKey(cacheKey);
|
|
233
|
-
return {
|
|
234
|
-
cacheKey,
|
|
235
|
-
integrity
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (process.env.NODE_ENV !== "production") {
|
|
240
|
-
logger.debug(`Precaching did not find a match for ${getFriendlyURL(request.url)}`);
|
|
241
|
-
}
|
|
242
|
-
return;
|
|
243
|
-
};
|
|
244
|
-
super(match, precacheController.strategy);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
class Router {
|
|
249
|
-
_routes;
|
|
250
|
-
_defaultHandlerMap;
|
|
251
|
-
_fetchListenerHandler = null;
|
|
252
|
-
_cacheListenerHandler = null;
|
|
253
|
-
_catchHandler;
|
|
254
|
-
constructor(){
|
|
255
|
-
this._routes = new Map();
|
|
256
|
-
this._defaultHandlerMap = new Map();
|
|
257
|
-
}
|
|
258
|
-
get routes() {
|
|
259
|
-
return this._routes;
|
|
260
|
-
}
|
|
261
|
-
addFetchListener() {
|
|
262
|
-
if (!this._fetchListenerHandler) {
|
|
263
|
-
this._fetchListenerHandler = (event)=>{
|
|
264
|
-
const { request } = event;
|
|
265
|
-
const responsePromise = this.handleRequest({
|
|
266
|
-
request,
|
|
267
|
-
event
|
|
268
|
-
});
|
|
269
|
-
if (responsePromise) {
|
|
270
|
-
event.respondWith(responsePromise);
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
self.addEventListener("fetch", this._fetchListenerHandler);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
removeFetchListener() {
|
|
277
|
-
if (this._fetchListenerHandler) {
|
|
278
|
-
self.removeEventListener("fetch", this._fetchListenerHandler);
|
|
279
|
-
this._fetchListenerHandler = null;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
addCacheListener() {
|
|
283
|
-
if (!this._cacheListenerHandler) {
|
|
284
|
-
this._cacheListenerHandler = (event)=>{
|
|
285
|
-
if (event.data && event.data.type === "CACHE_URLS") {
|
|
286
|
-
const { payload } = event.data;
|
|
287
|
-
if (process.env.NODE_ENV !== "production") {
|
|
288
|
-
logger.debug("Caching URLs from the window", payload.urlsToCache);
|
|
289
|
-
}
|
|
290
|
-
const requestPromises = Promise.all(payload.urlsToCache.map((entry)=>{
|
|
291
|
-
if (typeof entry === "string") {
|
|
292
|
-
entry = [
|
|
293
|
-
entry
|
|
294
|
-
];
|
|
295
|
-
}
|
|
296
|
-
const request = new Request(...entry);
|
|
297
|
-
return this.handleRequest({
|
|
298
|
-
request,
|
|
299
|
-
event
|
|
300
|
-
});
|
|
301
|
-
}));
|
|
302
|
-
event.waitUntil(requestPromises);
|
|
303
|
-
if (event.ports?.[0]) {
|
|
304
|
-
void requestPromises.then(()=>event.ports[0].postMessage(true));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
self.addEventListener("message", this._cacheListenerHandler);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
removeCacheListener() {
|
|
312
|
-
if (this._cacheListenerHandler) {
|
|
313
|
-
self.removeEventListener("message", this._cacheListenerHandler);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
handleRequest({ request, event }) {
|
|
317
|
-
if (process.env.NODE_ENV !== "production") {
|
|
318
|
-
finalAssertExports.isInstance(request, Request, {
|
|
319
|
-
moduleName: "serwist/legacy",
|
|
320
|
-
className: "Router",
|
|
321
|
-
funcName: "handleRequest",
|
|
322
|
-
paramName: "options.request"
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
const url = new URL(request.url, location.href);
|
|
326
|
-
if (!url.protocol.startsWith("http")) {
|
|
327
|
-
if (process.env.NODE_ENV !== "production") {
|
|
328
|
-
logger.debug("Router only supports URLs that start with 'http'.");
|
|
329
|
-
}
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const sameOrigin = url.origin === location.origin;
|
|
333
|
-
const { params, route } = this.findMatchingRoute({
|
|
334
|
-
event,
|
|
335
|
-
request,
|
|
336
|
-
sameOrigin,
|
|
337
|
-
url
|
|
338
|
-
});
|
|
339
|
-
let handler = route?.handler;
|
|
340
|
-
const debugMessages = [];
|
|
341
|
-
if (process.env.NODE_ENV !== "production") {
|
|
342
|
-
if (handler) {
|
|
343
|
-
debugMessages.push([
|
|
344
|
-
"Found a route to handle this request:",
|
|
345
|
-
route
|
|
346
|
-
]);
|
|
347
|
-
if (params) {
|
|
348
|
-
debugMessages.push([
|
|
349
|
-
`Passing the following params to the route's handler:`,
|
|
350
|
-
params
|
|
351
|
-
]);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
const method = request.method;
|
|
356
|
-
if (!handler && this._defaultHandlerMap.has(method)) {
|
|
357
|
-
if (process.env.NODE_ENV !== "production") {
|
|
358
|
-
debugMessages.push(`Failed to find a matching route. Falling back to the default handler for ${method}.`);
|
|
359
|
-
}
|
|
360
|
-
handler = this._defaultHandlerMap.get(method);
|
|
361
|
-
}
|
|
362
|
-
if (!handler) {
|
|
363
|
-
if (process.env.NODE_ENV !== "production") {
|
|
364
|
-
logger.debug(`No route found for: ${getFriendlyURL(url)}`);
|
|
365
|
-
}
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
if (process.env.NODE_ENV !== "production") {
|
|
369
|
-
logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);
|
|
370
|
-
for (const msg of debugMessages){
|
|
371
|
-
if (Array.isArray(msg)) {
|
|
372
|
-
logger.log(...msg);
|
|
373
|
-
} else {
|
|
374
|
-
logger.log(msg);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
logger.groupEnd();
|
|
378
|
-
}
|
|
379
|
-
let responsePromise;
|
|
380
|
-
try {
|
|
381
|
-
responsePromise = handler.handle({
|
|
382
|
-
url,
|
|
383
|
-
request,
|
|
384
|
-
event,
|
|
385
|
-
params
|
|
386
|
-
});
|
|
387
|
-
} catch (err) {
|
|
388
|
-
responsePromise = Promise.reject(err);
|
|
389
|
-
}
|
|
390
|
-
const catchHandler = route?.catchHandler;
|
|
391
|
-
if (responsePromise instanceof Promise && (this._catchHandler || catchHandler)) {
|
|
392
|
-
responsePromise = responsePromise.catch(async (err)=>{
|
|
393
|
-
if (catchHandler) {
|
|
394
|
-
if (process.env.NODE_ENV !== "production") {
|
|
395
|
-
logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to route's Catch Handler.`);
|
|
396
|
-
logger.error("Error thrown by:", route);
|
|
397
|
-
logger.error(err);
|
|
398
|
-
logger.groupEnd();
|
|
399
|
-
}
|
|
400
|
-
try {
|
|
401
|
-
return await catchHandler.handle({
|
|
402
|
-
url,
|
|
403
|
-
request,
|
|
404
|
-
event,
|
|
405
|
-
params
|
|
406
|
-
});
|
|
407
|
-
} catch (catchErr) {
|
|
408
|
-
if (catchErr instanceof Error) {
|
|
409
|
-
err = catchErr;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (this._catchHandler) {
|
|
414
|
-
if (process.env.NODE_ENV !== "production") {
|
|
415
|
-
logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to global Catch Handler.`);
|
|
416
|
-
logger.error("Error thrown by:", route);
|
|
417
|
-
logger.error(err);
|
|
418
|
-
logger.groupEnd();
|
|
419
|
-
}
|
|
420
|
-
return this._catchHandler.handle({
|
|
421
|
-
url,
|
|
422
|
-
request,
|
|
423
|
-
event
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
throw err;
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
return responsePromise;
|
|
430
|
-
}
|
|
431
|
-
findMatchingRoute({ url, sameOrigin, request, event }) {
|
|
432
|
-
const routes = this._routes.get(request.method) || [];
|
|
433
|
-
for (const route of routes){
|
|
434
|
-
let params;
|
|
435
|
-
const matchResult = route.match({
|
|
436
|
-
url,
|
|
437
|
-
sameOrigin,
|
|
438
|
-
request,
|
|
439
|
-
event
|
|
440
|
-
});
|
|
441
|
-
if (matchResult) {
|
|
442
|
-
if (process.env.NODE_ENV !== "production") {
|
|
443
|
-
if (matchResult instanceof Promise) {
|
|
444
|
-
logger.warn(`While routing ${getFriendlyURL(url)}, an async matchCallback function was used. Please convert the following route to use a synchronous matchCallback function:`, route);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
params = matchResult;
|
|
448
|
-
if (Array.isArray(params) && params.length === 0) {
|
|
449
|
-
params = undefined;
|
|
450
|
-
} else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0) {
|
|
451
|
-
params = undefined;
|
|
452
|
-
} else if (typeof matchResult === "boolean") {
|
|
453
|
-
params = undefined;
|
|
454
|
-
}
|
|
455
|
-
return {
|
|
456
|
-
route,
|
|
457
|
-
params
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return {};
|
|
462
|
-
}
|
|
463
|
-
setDefaultHandler(handler, method = defaultMethod) {
|
|
464
|
-
this._defaultHandlerMap.set(method, normalizeHandler(handler));
|
|
465
|
-
}
|
|
466
|
-
setCatchHandler(handler) {
|
|
467
|
-
this._catchHandler = normalizeHandler(handler);
|
|
468
|
-
}
|
|
469
|
-
registerCapture(capture, handler, method) {
|
|
470
|
-
const route = parseRoute(capture, handler, method);
|
|
471
|
-
this.registerRoute(route);
|
|
472
|
-
return route;
|
|
473
|
-
}
|
|
474
|
-
registerRoute(route) {
|
|
475
|
-
if (process.env.NODE_ENV !== "production") {
|
|
476
|
-
finalAssertExports.isType(route, "object", {
|
|
477
|
-
moduleName: "serwist/legacy",
|
|
478
|
-
className: "Router",
|
|
479
|
-
funcName: "registerRoute",
|
|
480
|
-
paramName: "route"
|
|
481
|
-
});
|
|
482
|
-
finalAssertExports.hasMethod(route, "match", {
|
|
483
|
-
moduleName: "serwist/legacy",
|
|
484
|
-
className: "Router",
|
|
485
|
-
funcName: "registerRoute",
|
|
486
|
-
paramName: "route"
|
|
487
|
-
});
|
|
488
|
-
finalAssertExports.isType(route.handler, "object", {
|
|
489
|
-
moduleName: "serwist/legacy",
|
|
490
|
-
className: "Router",
|
|
491
|
-
funcName: "registerRoute",
|
|
492
|
-
paramName: "route"
|
|
493
|
-
});
|
|
494
|
-
finalAssertExports.hasMethod(route.handler, "handle", {
|
|
495
|
-
moduleName: "serwist/legacy",
|
|
496
|
-
className: "Router",
|
|
497
|
-
funcName: "registerRoute",
|
|
498
|
-
paramName: "route.handler"
|
|
499
|
-
});
|
|
500
|
-
finalAssertExports.isType(route.method, "string", {
|
|
501
|
-
moduleName: "serwist/legacy",
|
|
502
|
-
className: "Router",
|
|
503
|
-
funcName: "registerRoute",
|
|
504
|
-
paramName: "route.method"
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
if (!this._routes.has(route.method)) {
|
|
508
|
-
this._routes.set(route.method, []);
|
|
509
|
-
}
|
|
510
|
-
this._routes.get(route.method).push(route);
|
|
511
|
-
}
|
|
512
|
-
unregisterRoute(route) {
|
|
513
|
-
if (!this._routes.has(route.method)) {
|
|
514
|
-
throw new SerwistError("unregister-route-but-not-found-with-method", {
|
|
515
|
-
method: route.method
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
const routeIndex = this._routes.get(route.method).indexOf(route);
|
|
519
|
-
if (routeIndex > -1) {
|
|
520
|
-
this._routes.get(route.method).splice(routeIndex, 1);
|
|
521
|
-
} else {
|
|
522
|
-
throw new SerwistError("unregister-route-route-not-registered");
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const addPlugins = (plugins)=>{
|
|
528
|
-
const precacheController = getSingletonPrecacheController();
|
|
529
|
-
precacheController.strategy.plugins.push(...plugins);
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
let defaultRouter = undefined;
|
|
533
|
-
const getSingletonRouter = ()=>{
|
|
534
|
-
if (!defaultRouter) {
|
|
535
|
-
defaultRouter = new Router();
|
|
536
|
-
defaultRouter.addFetchListener();
|
|
537
|
-
defaultRouter.addCacheListener();
|
|
538
|
-
}
|
|
539
|
-
return defaultRouter;
|
|
540
|
-
};
|
|
541
|
-
const setSingletonRouter = (router)=>{
|
|
542
|
-
if (defaultRouter) {
|
|
543
|
-
defaultRouter.removeFetchListener();
|
|
544
|
-
defaultRouter.removeCacheListener();
|
|
545
|
-
}
|
|
546
|
-
defaultRouter = router;
|
|
547
|
-
defaultRouter.addFetchListener();
|
|
548
|
-
defaultRouter.addCacheListener();
|
|
549
|
-
return defaultRouter;
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
const registerRoute = (capture, handler, method)=>{
|
|
553
|
-
return getSingletonRouter().registerCapture(capture, handler, method);
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
const addRoute = (options)=>{
|
|
557
|
-
const precacheRoute = new PrecacheRoute(getSingletonPrecacheController(), options);
|
|
558
|
-
registerRoute(precacheRoute);
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
const createHandlerBoundToURL = (url)=>{
|
|
562
|
-
const precacheController = getSingletonPrecacheController();
|
|
563
|
-
return precacheController.createHandlerBoundToURL(url);
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
const fallbacks = ({ precacheController = getSingletonPrecacheController(), router = getSingletonRouter(), runtimeCaching, entries, precacheOptions })=>{
|
|
567
|
-
precacheController.precache(entries);
|
|
568
|
-
router.registerRoute(new PrecacheRoute(precacheController, precacheOptions));
|
|
569
|
-
const fallbackPlugin = new PrecacheFallbackPlugin({
|
|
570
|
-
fallbackUrls: entries
|
|
571
|
-
});
|
|
572
|
-
runtimeCaching.forEach((cacheEntry)=>{
|
|
573
|
-
if (cacheEntry.handler instanceof Strategy && !cacheEntry.handler.plugins.some((plugin)=>"handlerDidError" in plugin)) {
|
|
574
|
-
cacheEntry.handler.plugins.push(fallbackPlugin);
|
|
575
|
-
}
|
|
576
|
-
return cacheEntry;
|
|
577
|
-
});
|
|
578
|
-
return runtimeCaching;
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
const getCacheKeyForURL = (url)=>{
|
|
582
|
-
const precacheController = getSingletonPrecacheController();
|
|
583
|
-
return precacheController.getCacheKeyForURL(url);
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
const handlePrecaching = ({ precacheController = getSingletonPrecacheController(), router = getSingletonRouter(), precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1 = false, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist })=>{
|
|
587
|
-
if (!!precacheEntries && precacheEntries.length > 0) {
|
|
588
|
-
precacheController.precache(precacheEntries);
|
|
589
|
-
router.registerRoute(new PrecacheRoute(precacheController, precacheOptions));
|
|
590
|
-
if (cleanupOutdatedCaches$1) cleanupOutdatedCaches();
|
|
591
|
-
if (navigateFallback) {
|
|
592
|
-
router.registerRoute(new NavigationRoute(createHandlerBoundToURL(navigateFallback), {
|
|
593
|
-
allowlist: navigateFallbackAllowlist,
|
|
594
|
-
denylist: navigateFallbackDenylist
|
|
595
|
-
}));
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
const QUEUE_NAME = "serwist-google-analytics";
|
|
601
|
-
const MAX_RETENTION_TIME = 60 * 48;
|
|
602
|
-
const GOOGLE_ANALYTICS_HOST = "www.google-analytics.com";
|
|
603
|
-
const GTM_HOST = "www.googletagmanager.com";
|
|
604
|
-
const ANALYTICS_JS_PATH = "/analytics.js";
|
|
605
|
-
const GTAG_JS_PATH = "/gtag/js";
|
|
606
|
-
const GTM_JS_PATH = "/gtm.js";
|
|
607
|
-
const COLLECT_PATHS_REGEX = /^\/(\w+\/)?collect/;
|
|
608
|
-
|
|
609
|
-
const createOnSyncCallback = (config)=>{
|
|
610
|
-
return async ({ queue })=>{
|
|
611
|
-
let entry = undefined;
|
|
612
|
-
while(entry = await queue.shiftRequest()){
|
|
613
|
-
const { request, timestamp } = entry;
|
|
614
|
-
const url = new URL(request.url);
|
|
615
|
-
try {
|
|
616
|
-
const params = request.method === "POST" ? new URLSearchParams(await request.clone().text()) : url.searchParams;
|
|
617
|
-
const originalHitTime = timestamp - (Number(params.get("qt")) || 0);
|
|
618
|
-
const queueTime = Date.now() - originalHitTime;
|
|
619
|
-
params.set("qt", String(queueTime));
|
|
620
|
-
if (config.parameterOverrides) {
|
|
621
|
-
for (const param of Object.keys(config.parameterOverrides)){
|
|
622
|
-
const value = config.parameterOverrides[param];
|
|
623
|
-
params.set(param, value);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
if (typeof config.hitFilter === "function") {
|
|
627
|
-
config.hitFilter.call(null, params);
|
|
628
|
-
}
|
|
629
|
-
await fetch(new Request(url.origin + url.pathname, {
|
|
630
|
-
body: params.toString(),
|
|
631
|
-
method: "POST",
|
|
632
|
-
mode: "cors",
|
|
633
|
-
credentials: "omit",
|
|
634
|
-
headers: {
|
|
635
|
-
"Content-Type": "text/plain"
|
|
636
|
-
}
|
|
637
|
-
}));
|
|
638
|
-
if (process.env.NODE_ENV !== "production") {
|
|
639
|
-
logger.log(`Request for '${getFriendlyURL(url.href)}' has been replayed`);
|
|
640
|
-
}
|
|
641
|
-
} catch (err) {
|
|
642
|
-
await queue.unshiftRequest(entry);
|
|
643
|
-
if (process.env.NODE_ENV !== "production") {
|
|
644
|
-
logger.log(`Request for '${getFriendlyURL(url.href)}' failed to replay, putting it back in the queue.`);
|
|
645
|
-
}
|
|
646
|
-
throw err;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
if (process.env.NODE_ENV !== "production") {
|
|
650
|
-
logger.log("All Google Analytics request successfully replayed; " + "the queue is now empty!");
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
};
|
|
654
|
-
const createCollectRoutes = (bgSyncPlugin)=>{
|
|
655
|
-
const match = ({ url })=>url.hostname === GOOGLE_ANALYTICS_HOST && COLLECT_PATHS_REGEX.test(url.pathname);
|
|
656
|
-
const handler = new NetworkOnly({
|
|
657
|
-
plugins: [
|
|
658
|
-
bgSyncPlugin
|
|
659
|
-
]
|
|
660
|
-
});
|
|
661
|
-
return [
|
|
662
|
-
new Route(match, handler, "GET"),
|
|
663
|
-
new Route(match, handler, "POST")
|
|
664
|
-
];
|
|
665
|
-
};
|
|
666
|
-
const createAnalyticsJsRoute = (cacheName)=>{
|
|
667
|
-
const match = ({ url })=>url.hostname === GOOGLE_ANALYTICS_HOST && url.pathname === ANALYTICS_JS_PATH;
|
|
668
|
-
const handler = new NetworkFirst({
|
|
669
|
-
cacheName
|
|
670
|
-
});
|
|
671
|
-
return new Route(match, handler, "GET");
|
|
672
|
-
};
|
|
673
|
-
const createGtagJsRoute = (cacheName)=>{
|
|
674
|
-
const match = ({ url })=>url.hostname === GTM_HOST && url.pathname === GTAG_JS_PATH;
|
|
675
|
-
const handler = new NetworkFirst({
|
|
676
|
-
cacheName
|
|
677
|
-
});
|
|
678
|
-
return new Route(match, handler, "GET");
|
|
679
|
-
};
|
|
680
|
-
const createGtmJsRoute = (cacheName)=>{
|
|
681
|
-
const match = ({ url })=>url.hostname === GTM_HOST && url.pathname === GTM_JS_PATH;
|
|
682
|
-
const handler = new NetworkFirst({
|
|
683
|
-
cacheName
|
|
684
|
-
});
|
|
685
|
-
return new Route(match, handler, "GET");
|
|
686
|
-
};
|
|
687
|
-
const initializeGoogleAnalytics = ({ router = getSingletonRouter(), cacheName, ...options } = {})=>{
|
|
688
|
-
const resolvedCacheName = cacheNames.getGoogleAnalyticsName(cacheName);
|
|
689
|
-
const bgSyncPlugin = new BackgroundSyncPlugin(QUEUE_NAME, {
|
|
690
|
-
maxRetentionTime: MAX_RETENTION_TIME,
|
|
691
|
-
onSync: createOnSyncCallback(options)
|
|
692
|
-
});
|
|
693
|
-
const routes = [
|
|
694
|
-
createGtmJsRoute(resolvedCacheName),
|
|
695
|
-
createAnalyticsJsRoute(resolvedCacheName),
|
|
696
|
-
createGtagJsRoute(resolvedCacheName),
|
|
697
|
-
...createCollectRoutes(bgSyncPlugin)
|
|
698
|
-
];
|
|
699
|
-
for (const route of routes){
|
|
700
|
-
router.registerRoute(route);
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
const registerRuntimeCaching = (...runtimeCachingList)=>{
|
|
705
|
-
for (const entry of runtimeCachingList){
|
|
706
|
-
registerRoute(entry.matcher, entry.handler, entry.method);
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
const installSerwist = ({ precacheController = getSingletonPrecacheController(), router = getSingletonRouter(), precacheEntries, precacheOptions, cleanupOutdatedCaches, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist, skipWaiting, importScripts, navigationPreload = false, cacheId, clientsClaim: clientsClaim$1 = false, runtimeCaching, offlineAnalyticsConfig, disableDevLogs: disableDevLogs$1 = false, fallbacks: fallbacks$1 })=>{
|
|
711
|
-
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
|
|
712
|
-
if (navigationPreload) enableNavigationPreload();
|
|
713
|
-
if (cacheId !== undefined) {
|
|
714
|
-
setCacheNameDetails({
|
|
715
|
-
prefix: cacheId
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
if (skipWaiting) {
|
|
719
|
-
self.skipWaiting();
|
|
720
|
-
} else {
|
|
721
|
-
self.addEventListener("message", (event)=>{
|
|
722
|
-
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
723
|
-
self.skipWaiting();
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
if (clientsClaim$1) clientsClaim();
|
|
728
|
-
handlePrecaching({
|
|
729
|
-
precacheController,
|
|
730
|
-
router,
|
|
731
|
-
precacheEntries,
|
|
732
|
-
precacheOptions,
|
|
733
|
-
cleanupOutdatedCaches,
|
|
734
|
-
navigateFallback,
|
|
735
|
-
navigateFallbackAllowlist,
|
|
736
|
-
navigateFallbackDenylist
|
|
737
|
-
});
|
|
738
|
-
if (runtimeCaching !== undefined) {
|
|
739
|
-
if (fallbacks$1 !== undefined) {
|
|
740
|
-
runtimeCaching = fallbacks({
|
|
741
|
-
precacheController,
|
|
742
|
-
router,
|
|
743
|
-
runtimeCaching,
|
|
744
|
-
entries: fallbacks$1.entries,
|
|
745
|
-
precacheOptions
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
registerRuntimeCaching(...runtimeCaching);
|
|
749
|
-
}
|
|
750
|
-
if (offlineAnalyticsConfig !== undefined) {
|
|
751
|
-
if (typeof offlineAnalyticsConfig === "boolean") {
|
|
752
|
-
offlineAnalyticsConfig && initializeGoogleAnalytics({
|
|
753
|
-
router
|
|
754
|
-
});
|
|
755
|
-
} else {
|
|
756
|
-
initializeGoogleAnalytics({
|
|
757
|
-
...offlineAnalyticsConfig,
|
|
758
|
-
router
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
if (disableDevLogs$1) disableDevLogs();
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
const matchPrecache = (request)=>{
|
|
766
|
-
return getSingletonPrecacheController().matchPrecache(request);
|
|
767
|
-
};
|
|
768
|
-
|
|
769
|
-
const precache = (entries)=>{
|
|
770
|
-
getSingletonPrecacheController().precache(entries);
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
const precacheAndRoute = (entries, options)=>{
|
|
774
|
-
precache(entries);
|
|
775
|
-
addRoute(options);
|
|
776
|
-
};
|
|
777
|
-
|
|
778
|
-
const setCatchHandler = (handler)=>{
|
|
779
|
-
getSingletonRouter().setCatchHandler(handler);
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
const setDefaultHandler = (handler)=>{
|
|
783
|
-
getSingletonRouter().setDefaultHandler(handler);
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
const unregisterRoute = (route)=>{
|
|
787
|
-
getSingletonRouter().unregisterRoute(route);
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
export { PrecacheController, PrecacheFallbackPlugin, PrecacheRoute, Router, addPlugins, addRoute, createHandlerBoundToURL, fallbacks, getCacheKeyForURL, getSingletonPrecacheController, getSingletonRouter, handlePrecaching, initializeGoogleAnalytics, installSerwist, matchPrecache, precache, precacheAndRoute, registerRoute, registerRuntimeCaching, setCatchHandler, setDefaultHandler, setSingletonPrecacheController, setSingletonRouter, unregisterRoute };
|