@serwist/sw 9.0.0-preview.20 → 9.0.0-preview.24
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/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -156
- package/package.json +5 -40
- package/src/index.ts +5 -22
- package/README.md +0 -1
- package/dist/abstractions/Serwist.d.ts +0 -82
- package/dist/abstractions/Serwist.d.ts.map +0 -1
- package/dist/abstractions/disableDevLogs.d.ts +0 -7
- package/dist/abstractions/disableDevLogs.d.ts.map +0 -1
- package/dist/abstractions/fallbacks.d.ts +0 -39
- package/dist/abstractions/fallbacks.d.ts.map +0 -1
- package/dist/abstractions/handlePrecaching.d.ts +0 -39
- package/dist/abstractions/handlePrecaching.d.ts.map +0 -1
- package/dist/abstractions/installSerwist.d.ts +0 -15
- package/dist/abstractions/installSerwist.d.ts.map +0 -1
- package/dist/abstractions/navigationPreload.d.ts +0 -20
- package/dist/abstractions/navigationPreload.d.ts.map +0 -1
- package/dist/abstractions/registerRuntimeCaching.d.ts +0 -11
- package/dist/abstractions/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/abstractions/types.d.ts +0 -29
- package/dist/abstractions/types.d.ts.map +0 -1
- package/dist/chunks/NavigationRoute.js +0 -54
- package/dist/chunks/NetworkOnly.js +0 -193
- package/dist/chunks/PrecacheFallbackPlugin.js +0 -573
- package/dist/chunks/Strategy.js +0 -410
- package/dist/chunks/precacheAndRoute.js +0 -113
- package/dist/chunks/registerRoute.js +0 -7
- package/dist/chunks/singletonPrecacheController.js +0 -433
- package/dist/chunks/singletonRouter.js +0 -435
- package/dist/index.plugins.d.ts +0 -41
- package/dist/index.plugins.d.ts.map +0 -1
- package/dist/index.plugins.js +0 -671
- package/dist/index.precaching.d.ts +0 -25
- package/dist/index.precaching.d.ts.map +0 -1
- package/dist/index.precaching.js +0 -24
- package/dist/index.routing.d.ts +0 -15
- package/dist/index.routing.d.ts.map +0 -1
- package/dist/index.routing.js +0 -19
- package/dist/index.strategies.d.ts +0 -22
- package/dist/index.strategies.d.ts.map +0 -1
- package/dist/index.strategies.js +0 -146
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +0 -23
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/Queue.d.ts +0 -166
- package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueDb.d.ts +0 -90
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueStore.d.ts +0 -75
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/StorableRequest.d.ts +0 -51
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -45
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +0 -27
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +0 -11
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/types.d.ts +0 -34
- package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +0 -40
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +0 -27
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/CacheExpiration.d.ts +0 -66
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
- package/dist/plugins/expiration/ExpirationPlugin.d.ts +0 -116
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +0 -73
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/constants.d.ts +0 -10
- package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/initialize.d.ts +0 -34
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +0 -54
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +0 -19
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts +0 -18
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -14
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +0 -12
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
- package/dist/precaching/PrecacheController.d.ts +0 -145
- package/dist/precaching/PrecacheController.d.ts.map +0 -1
- package/dist/precaching/PrecacheRoute.d.ts +0 -20
- package/dist/precaching/PrecacheRoute.d.ts.map +0 -1
- package/dist/precaching/PrecacheStrategy.d.ts +0 -68
- package/dist/precaching/PrecacheStrategy.d.ts.map +0 -1
- package/dist/precaching/addPlugins.d.ts +0 -8
- package/dist/precaching/addPlugins.d.ts.map +0 -1
- package/dist/precaching/addRoute.d.ts +0 -15
- package/dist/precaching/addRoute.d.ts.map +0 -1
- package/dist/precaching/cleanupOutdatedCaches.d.ts +0 -6
- package/dist/precaching/cleanupOutdatedCaches.d.ts.map +0 -1
- package/dist/precaching/createHandlerBoundToURL.d.ts +0 -17
- package/dist/precaching/createHandlerBoundToURL.d.ts.map +0 -1
- package/dist/precaching/getCacheKeyForURL.d.ts +0 -20
- package/dist/precaching/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/precaching/matchPrecache.d.ts +0 -14
- package/dist/precaching/matchPrecache.d.ts.map +0 -1
- package/dist/precaching/precache.d.ts +0 -19
- package/dist/precaching/precache.d.ts.map +0 -1
- package/dist/precaching/precacheAndRoute.d.ts +0 -14
- package/dist/precaching/precacheAndRoute.d.ts.map +0 -1
- package/dist/precaching/singletonPrecacheController.d.ts +0 -38
- package/dist/precaching/singletonPrecacheController.d.ts.map +0 -1
- package/dist/precaching/types.d.ts +0 -37
- package/dist/precaching/types.d.ts.map +0 -1
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +0 -17
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +0 -15
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/precaching/utils/createCacheKey.d.ts +0 -16
- package/dist/precaching/utils/createCacheKey.d.ts.map +0 -1
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts +0 -18
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +0 -1
- package/dist/precaching/utils/generateURLVariations.d.ts +0 -12
- package/dist/precaching/utils/generateURLVariations.d.ts.map +0 -1
- package/dist/precaching/utils/getCacheKeyForURL.d.ts +0 -14
- package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/precaching/utils/printCleanupDetails.d.ts +0 -6
- package/dist/precaching/utils/printCleanupDetails.d.ts.map +0 -1
- package/dist/precaching/utils/printInstallDetails.d.ts +0 -7
- package/dist/precaching/utils/printInstallDetails.d.ts.map +0 -1
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +0 -12
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +0 -1
- package/dist/routing/NavigationRoute.d.ts +0 -57
- package/dist/routing/NavigationRoute.d.ts.map +0 -1
- package/dist/routing/RegExpRoute.d.ts +0 -24
- package/dist/routing/RegExpRoute.d.ts.map +0 -1
- package/dist/routing/Route.d.ts +0 -33
- package/dist/routing/Route.d.ts.map +0 -1
- package/dist/routing/Router.d.ts +0 -150
- package/dist/routing/Router.d.ts.map +0 -1
- package/dist/routing/parseRoute.d.ts +0 -16
- package/dist/routing/parseRoute.d.ts.map +0 -1
- package/dist/routing/registerRoute.d.ts +0 -15
- package/dist/routing/registerRoute.d.ts.map +0 -1
- package/dist/routing/setCatchHandler.d.ts +0 -9
- package/dist/routing/setCatchHandler.d.ts.map +0 -1
- package/dist/routing/setDefaultHandler.d.ts +0 -12
- package/dist/routing/setDefaultHandler.d.ts.map +0 -1
- package/dist/routing/singletonRouter.d.ts +0 -47
- package/dist/routing/singletonRouter.d.ts.map +0 -1
- package/dist/routing/unregisterRoute.d.ts +0 -8
- package/dist/routing/unregisterRoute.d.ts.map +0 -1
- package/dist/routing/utils/constants.d.ts +0 -15
- package/dist/routing/utils/constants.d.ts.map +0 -1
- package/dist/routing/utils/normalizeHandler.d.ts +0 -10
- package/dist/routing/utils/normalizeHandler.d.ts.map +0 -1
- package/dist/strategies/CacheFirst.d.ts +0 -23
- package/dist/strategies/CacheFirst.d.ts.map +0 -1
- package/dist/strategies/CacheOnly.d.ts +0 -20
- package/dist/strategies/CacheOnly.d.ts.map +0 -1
- package/dist/strategies/NetworkFirst.d.ts +0 -61
- package/dist/strategies/NetworkFirst.d.ts.map +0 -1
- package/dist/strategies/NetworkOnly.d.ts +0 -32
- package/dist/strategies/NetworkOnly.d.ts.map +0 -1
- package/dist/strategies/StaleWhileRevalidate.d.ts +0 -35
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
- package/dist/strategies/Strategy.d.ts +0 -83
- package/dist/strategies/Strategy.d.ts.map +0 -1
- package/dist/strategies/StrategyHandler.d.ts +0 -189
- package/dist/strategies/StrategyHandler.d.ts.map +0 -1
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
- package/dist/strategies/utils/messages.d.ts +0 -5
- package/dist/strategies/utils/messages.d.ts.map +0 -1
- package/src/abstractions/Serwist.ts +0 -177
- package/src/abstractions/disableDevLogs.ts +0 -10
- package/src/abstractions/fallbacks.ts +0 -65
- package/src/abstractions/handlePrecaching.ts +0 -65
- package/src/abstractions/installSerwist.ts +0 -28
- package/src/abstractions/navigationPreload.ts +0 -64
- package/src/abstractions/registerRuntimeCaching.ts +0 -17
- package/src/abstractions/types.ts +0 -29
- package/src/index.plugins.ts +0 -95
- package/src/index.precaching.ts +0 -41
- package/src/index.routing.ts +0 -28
- package/src/index.strategies.ts +0 -26
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +0 -39
- package/src/plugins/backgroundSync/Queue.ts +0 -438
- package/src/plugins/backgroundSync/QueueDb.ts +0 -176
- package/src/plugins/backgroundSync/QueueStore.ts +0 -161
- package/src/plugins/backgroundSync/StorableRequest.ts +0 -142
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +0 -159
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +0 -43
- package/src/plugins/broadcastUpdate/constants.ts +0 -12
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +0 -48
- package/src/plugins/broadcastUpdate/types.ts +0 -37
- package/src/plugins/cacheableResponse/CacheableResponse.ts +0 -141
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +0 -46
- package/src/plugins/expiration/CacheExpiration.ts +0 -192
- package/src/plugins/expiration/ExpirationPlugin.ts +0 -297
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +0 -184
- package/src/plugins/googleAnalytics/constants.ts +0 -22
- package/src/plugins/googleAnalytics/initialize.ts +0 -213
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +0 -86
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +0 -39
- package/src/plugins/rangeRequests/createPartialResponse.ts +0 -92
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +0 -58
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +0 -54
- package/src/precaching/PrecacheController.ts +0 -332
- package/src/precaching/PrecacheRoute.ts +0 -50
- package/src/precaching/PrecacheStrategy.ts +0 -238
- package/src/precaching/addPlugins.ts +0 -21
- package/src/precaching/addRoute.ts +0 -30
- package/src/precaching/cleanupOutdatedCaches.ts +0 -33
- package/src/precaching/createHandlerBoundToURL.ts +0 -30
- package/src/precaching/getCacheKeyForURL.ts +0 -33
- package/src/precaching/matchPrecache.ts +0 -25
- package/src/precaching/precache.ts +0 -31
- package/src/precaching/precacheAndRoute.ts +0 -27
- package/src/precaching/singletonPrecacheController.ts +0 -57
- package/src/precaching/types.ts +0 -46
- package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +0 -36
- package/src/precaching/utils/PrecacheInstallReportPlugin.ts +0 -49
- package/src/precaching/utils/createCacheKey.ts +0 -68
- package/src/precaching/utils/deleteOutdatedCaches.ts +0 -40
- package/src/precaching/utils/generateURLVariations.ts +0 -55
- package/src/precaching/utils/getCacheKeyForURL.ts +0 -36
- package/src/precaching/utils/printCleanupDetails.ts +0 -38
- package/src/precaching/utils/printInstallDetails.ts +0 -53
- package/src/precaching/utils/removeIgnoredSearchParams.ts +0 -29
- package/src/routing/NavigationRoute.ts +0 -119
- package/src/routing/RegExpRoute.ts +0 -74
- package/src/routing/Route.ts +0 -68
- package/src/routing/Router.ts +0 -481
- package/src/routing/parseRoute.ts +0 -78
- package/src/routing/registerRoute.ts +0 -27
- package/src/routing/setCatchHandler.ts +0 -21
- package/src/routing/setDefaultHandler.ts +0 -24
- package/src/routing/singletonRouter.ts +0 -76
- package/src/routing/unregisterRoute.ts +0 -11
- package/src/routing/utils/constants.ts +0 -24
- package/src/routing/utils/normalizeHandler.ts +0 -40
- package/src/strategies/CacheFirst.ts +0 -87
- package/src/strategies/CacheOnly.ts +0 -58
- package/src/strategies/NetworkFirst.ts +0 -228
- package/src/strategies/NetworkOnly.ts +0 -96
- package/src/strategies/StaleWhileRevalidate.ts +0 -109
- package/src/strategies/Strategy.ts +0 -202
- package/src/strategies/StrategyHandler.ts +0 -557
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +0 -26
- package/src/strategies/utils/messages.ts +0 -20
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { HandlerDidErrorCallbackParam } from "@serwist/core";
|
|
2
|
-
import { PrecacheFallbackPlugin } from "../plugins/precaching/PrecacheFallbackPlugin.js";
|
|
3
|
-
import type { PrecacheFallbackEntry } from "../plugins/precaching/PrecacheFallbackPlugin.js";
|
|
4
|
-
import { precacheAndRoute } from "../precaching/precacheAndRoute.js";
|
|
5
|
-
import type { PrecacheRouteOptions } from "../precaching/types.js";
|
|
6
|
-
import { Strategy } from "../strategies/Strategy.js";
|
|
7
|
-
import type { RuntimeCaching } from "./types.js";
|
|
8
|
-
|
|
9
|
-
export type FallbackMatcher = (_: HandlerDidErrorCallbackParam) => boolean;
|
|
10
|
-
|
|
11
|
-
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
12
|
-
/**
|
|
13
|
-
* The revision used for precaching.
|
|
14
|
-
*/
|
|
15
|
-
revision: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface FallbacksOptions {
|
|
19
|
-
/**
|
|
20
|
-
* Your previous `RuntimeCaching` array.
|
|
21
|
-
*/
|
|
22
|
-
runtimeCaching: RuntimeCaching[];
|
|
23
|
-
/**
|
|
24
|
-
* A list of fallback entries.
|
|
25
|
-
*/
|
|
26
|
-
entries: FallbackEntry[];
|
|
27
|
-
/**
|
|
28
|
-
* Precache options that will be used for your
|
|
29
|
-
* fallback entries.
|
|
30
|
-
*/
|
|
31
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Precaches routes so that they can be used as a fallback when
|
|
36
|
-
* a Strategy fails to generate a response.
|
|
37
|
-
*
|
|
38
|
-
* Note: This function mutates `runtimeCaching`!
|
|
39
|
-
*
|
|
40
|
-
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
41
|
-
* @param options
|
|
42
|
-
* @returns The modified `RuntimeCaching` array. Using this value
|
|
43
|
-
* is not needed, as it is simply the array in `options`.
|
|
44
|
-
*/
|
|
45
|
-
export const fallbacks = ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions): RuntimeCaching[] => {
|
|
46
|
-
precacheAndRoute(entries, precacheOptions);
|
|
47
|
-
|
|
48
|
-
const fallbackPlugin = new PrecacheFallbackPlugin({
|
|
49
|
-
fallbackUrls: entries,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
runtimeCaching.forEach((cacheEntry) => {
|
|
53
|
-
if (
|
|
54
|
-
cacheEntry.handler instanceof Strategy &&
|
|
55
|
-
// PrecacheFallbackPlugin also has `handlerDidError`, so we don't need to check for its instances.
|
|
56
|
-
!cacheEntry.handler.plugins.some((plugin) => "handlerDidError" in plugin)
|
|
57
|
-
) {
|
|
58
|
-
cacheEntry.handler.plugins.push(fallbackPlugin);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return cacheEntry;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return runtimeCaching;
|
|
65
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl } from "../precaching/cleanupOutdatedCaches.js";
|
|
2
|
-
import { createHandlerBoundToURL } from "../precaching/createHandlerBoundToURL.js";
|
|
3
|
-
import { precacheAndRoute } from "../precaching/precacheAndRoute.js";
|
|
4
|
-
import type { PrecacheEntry, PrecacheRouteOptions } from "../precaching/types.js";
|
|
5
|
-
import { NavigationRoute } from "../routing/NavigationRoute.js";
|
|
6
|
-
import { registerRoute } from "../routing/registerRoute.js";
|
|
7
|
-
|
|
8
|
-
export interface HandlePrecachingOptions {
|
|
9
|
-
/**
|
|
10
|
-
* A list of fallback entries.
|
|
11
|
-
*/
|
|
12
|
-
precacheEntries?: (PrecacheEntry | string)[];
|
|
13
|
-
/**
|
|
14
|
-
* Precache options for the provided entries.
|
|
15
|
-
*/
|
|
16
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
17
|
-
/**
|
|
18
|
-
* Whether outdated caches should be removed.
|
|
19
|
-
*
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
cleanupOutdatedCaches?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* An URL that should point to a HTML file with which navigation requests for URLs that aren't
|
|
25
|
-
* precached will be fulfilled.
|
|
26
|
-
*/
|
|
27
|
-
navigateFallback?: string;
|
|
28
|
-
/**
|
|
29
|
-
* URLs that should be allowed to use the `navigateFallback` handler.
|
|
30
|
-
*/
|
|
31
|
-
navigateFallbackAllowlist?: RegExp[];
|
|
32
|
-
/**
|
|
33
|
-
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
|
|
34
|
-
* over `navigateFallbackAllowlist`.
|
|
35
|
-
*/
|
|
36
|
-
navigateFallbackDenylist?: RegExp[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Handles a list of precache entries and cleans up outdated caches.
|
|
41
|
-
*
|
|
42
|
-
* @see https://serwist.pages.dev/docs/sw/handle-precaching
|
|
43
|
-
* @param options
|
|
44
|
-
*/
|
|
45
|
-
export const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches = false, ...options }: HandlePrecachingOptions): void => {
|
|
46
|
-
if (!!precacheEntries && precacheEntries.length > 0) {
|
|
47
|
-
/**
|
|
48
|
-
* The precacheAndRoute() method efficiently caches and responds to
|
|
49
|
-
* requests for URLs in the manifest.
|
|
50
|
-
* See https://goo.gl/S9QRab
|
|
51
|
-
*/
|
|
52
|
-
precacheAndRoute(precacheEntries, precacheOptions);
|
|
53
|
-
|
|
54
|
-
if (cleanupOutdatedCaches) cleanupOutdatedCachesImpl();
|
|
55
|
-
|
|
56
|
-
if (options.navigateFallback) {
|
|
57
|
-
registerRoute(
|
|
58
|
-
new NavigationRoute(createHandlerBoundToURL(options.navigateFallback), {
|
|
59
|
-
allowlist: options.navigateFallbackAllowlist,
|
|
60
|
-
denylist: options.navigateFallbackDenylist,
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { logger } from "@serwist/core/internal";
|
|
2
|
-
import { getSingletonPrecacheController } from "../precaching/singletonPrecacheController.js";
|
|
3
|
-
import { getSingletonRouter } from "../routing/singletonRouter.js";
|
|
4
|
-
import { Serwist, type SerwistInstallOptions } from "./Serwist.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Options for `installSerwist`.
|
|
8
|
-
*
|
|
9
|
-
* @deprecated
|
|
10
|
-
*/
|
|
11
|
-
export type InstallSerwistOptions = SerwistInstallOptions;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Abstracts away the core APIs of Serwist.
|
|
15
|
-
*
|
|
16
|
-
* @param options - `installSerwist` options.
|
|
17
|
-
* @deprecated
|
|
18
|
-
*/
|
|
19
|
-
export const installSerwist = (options: InstallSerwistOptions): void => {
|
|
20
|
-
if (process.env.NODE_ENV !== "production") {
|
|
21
|
-
logger.warn("'installSerwist' has been deprecated. Please migrate to 'new Serwist().install()'.");
|
|
22
|
-
}
|
|
23
|
-
const serwist = new Serwist({
|
|
24
|
-
precacheController: getSingletonPrecacheController(),
|
|
25
|
-
router: getSingletonRouter(),
|
|
26
|
-
});
|
|
27
|
-
serwist.install(options);
|
|
28
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { logger } from "@serwist/core/internal";
|
|
2
|
-
|
|
3
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Checks whether the current browser supports
|
|
7
|
-
* navigation preloading.
|
|
8
|
-
*
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export const isNavigationPreloadSupported = (): boolean => {
|
|
12
|
-
return Boolean(self.registration?.navigationPreload);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* If the browser supports navigation preloading, then this will enable it.
|
|
17
|
-
*
|
|
18
|
-
* @param headerValue Optional. Allows developers to override the value of
|
|
19
|
-
* the `Service-Worker-Navigation-Preload` header which will be sent to the
|
|
20
|
-
* server when making the navigation request.
|
|
21
|
-
*/
|
|
22
|
-
export const enableNavigationPreload = (headerValue?: string): void => {
|
|
23
|
-
if (isNavigationPreloadSupported()) {
|
|
24
|
-
self.addEventListener("activate", (event) => {
|
|
25
|
-
event.waitUntil(
|
|
26
|
-
self.registration.navigationPreload.enable().then(() => {
|
|
27
|
-
// Defaults to Service-Worker-Navigation-Preload: true if not set.
|
|
28
|
-
if (headerValue) {
|
|
29
|
-
void self.registration.navigationPreload.setHeaderValue(headerValue);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (process.env.NODE_ENV !== "production") {
|
|
33
|
-
logger.log("Navigation preloading is enabled.");
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
if (process.env.NODE_ENV !== "production") {
|
|
40
|
-
logger.log("Navigation preloading is not supported in this browser.");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* If the browser supports navigation preloading, then this will disable it.
|
|
47
|
-
*/
|
|
48
|
-
export const disableNavigationPreload = (): void => {
|
|
49
|
-
if (isNavigationPreloadSupported()) {
|
|
50
|
-
self.addEventListener("activate", (event: ExtendableEvent) => {
|
|
51
|
-
event.waitUntil(
|
|
52
|
-
self.registration.navigationPreload.disable().then(() => {
|
|
53
|
-
if (process.env.NODE_ENV !== "production") {
|
|
54
|
-
logger.log("Navigation preloading is disabled.");
|
|
55
|
-
}
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
if (process.env.NODE_ENV !== "production") {
|
|
61
|
-
logger.log("Navigation preloading is not supported in this browser.");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { registerRoute } from "../routing/registerRoute.js";
|
|
2
|
-
|
|
3
|
-
import type { RuntimeCaching } from "./types.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Registers caching strategies to a singleton Router instance. It is a simple
|
|
7
|
-
* syntatic sugar for `@serwist/routing.registerRoute`.
|
|
8
|
-
*
|
|
9
|
-
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
10
|
-
* @param runtimeCachingList
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export const registerRuntimeCaching = (...runtimeCachingList: RuntimeCaching[]): void => {
|
|
14
|
-
for (const entry of runtimeCachingList) {
|
|
15
|
-
registerRoute(entry.matcher, entry.handler, entry.method);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
-
import type { HTTPMethod } from "../routing/utils/constants.js";
|
|
3
|
-
|
|
4
|
-
export interface RuntimeCaching {
|
|
5
|
-
/**
|
|
6
|
-
* The HTTP method to match against. The default value of `'GET'` is normally
|
|
7
|
-
* sufficient, unless you explicitly need to match `'POST'`, `'PUT'`, or
|
|
8
|
-
* another type of request.
|
|
9
|
-
* @default "GET"
|
|
10
|
-
*/
|
|
11
|
-
method?: HTTPMethod;
|
|
12
|
-
/**
|
|
13
|
-
* This match criteria determines whether the configured handler will
|
|
14
|
-
* generate a response for any requests that don't match one of the precached
|
|
15
|
-
* URLs. If multiple `RuntimeCaching` routes are defined, then the first one
|
|
16
|
-
* whose `matcher` matches will be the one that responds.
|
|
17
|
-
*
|
|
18
|
-
* This value directly maps to the first parameter passed to
|
|
19
|
-
* `@serwist/routing.registerRoute`. It's recommended to use a
|
|
20
|
-
* `@serwist/core.RouteMatchCallback` function for greatest flexibility.
|
|
21
|
-
*/
|
|
22
|
-
matcher: RegExp | string | RouteMatchCallback;
|
|
23
|
-
/**
|
|
24
|
-
* This determines how the runtime route will generate a response. It
|
|
25
|
-
* can be a `@serwist/core.RouteHandler` callback function with custom
|
|
26
|
-
* response logic.
|
|
27
|
-
*/
|
|
28
|
-
handler: RouteHandler;
|
|
29
|
-
}
|
package/src/index.plugins.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { BackgroundSyncPlugin } from "./plugins/backgroundSync/BackgroundSyncPlugin.js";
|
|
2
|
-
import type { QueueEntry as BackgroundSyncQueueEntry, QueueOptions as BackgroundSyncQueueOptions } from "./plugins/backgroundSync/Queue.js";
|
|
3
|
-
import { Queue as BackgroundSyncQueue } from "./plugins/backgroundSync/Queue.js";
|
|
4
|
-
import { QueueStore as BackgroundSyncQueueStore } from "./plugins/backgroundSync/QueueStore.js";
|
|
5
|
-
import { StorableRequest } from "./plugins/backgroundSync/StorableRequest.js";
|
|
6
|
-
import { BroadcastCacheUpdate } from "./plugins/broadcastUpdate/BroadcastCacheUpdate.js";
|
|
7
|
-
import { BroadcastUpdatePlugin } from "./plugins/broadcastUpdate/BroadcastUpdatePlugin.js";
|
|
8
|
-
import {
|
|
9
|
-
CACHE_UPDATED_MESSAGE_META as BROADCAST_UPDATE_MESSAGE_META,
|
|
10
|
-
CACHE_UPDATED_MESSAGE_TYPE as BROADCAST_UPDATE_MESSAGE_TYPE,
|
|
11
|
-
defaultHeadersToCheck as BROADCAST_UPDATE_DEFAULT_HEADERS,
|
|
12
|
-
} from "./plugins/broadcastUpdate/constants.js";
|
|
13
|
-
import { responsesAreSame } from "./plugins/broadcastUpdate/responsesAreSame.js";
|
|
14
|
-
import type { BroadcastCacheUpdateOptions, BroadcastMessage, BroadcastPayload, BroadcastPayloadGenerator } from "./plugins/broadcastUpdate/types.js";
|
|
15
|
-
import type { CacheableResponseOptions } from "./plugins/cacheableResponse/CacheableResponse.js";
|
|
16
|
-
import { CacheableResponse } from "./plugins/cacheableResponse/CacheableResponse.js";
|
|
17
|
-
import { CacheableResponsePlugin } from "./plugins/cacheableResponse/CacheableResponsePlugin.js";
|
|
18
|
-
import { CacheExpiration } from "./plugins/expiration/CacheExpiration.js";
|
|
19
|
-
import type { ExpirationPluginOptions } from "./plugins/expiration/ExpirationPlugin.js";
|
|
20
|
-
import { ExpirationPlugin } from "./plugins/expiration/ExpirationPlugin.js";
|
|
21
|
-
import type { GoogleAnalyticsInitializeOptions } from "./plugins/googleAnalytics/initialize.js";
|
|
22
|
-
import { initialize as initializeGoogleAnalytics } from "./plugins/googleAnalytics/initialize.js";
|
|
23
|
-
import type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./plugins/precaching/PrecacheFallbackPlugin.js";
|
|
24
|
-
import { PrecacheFallbackPlugin } from "./plugins/precaching/PrecacheFallbackPlugin.js";
|
|
25
|
-
import { RangeRequestsPlugin } from "./plugins/rangeRequests/RangeRequestsPlugin.js";
|
|
26
|
-
import { createPartialResponse } from "./plugins/rangeRequests/createPartialResponse.js";
|
|
27
|
-
|
|
28
|
-
// See https://github.com/GoogleChrome/workbox/issues/2946
|
|
29
|
-
interface SyncManager {
|
|
30
|
-
getTags(): Promise<string[]>;
|
|
31
|
-
register(tag: string): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare global {
|
|
35
|
-
interface ServiceWorkerRegistration {
|
|
36
|
-
readonly sync: SyncManager;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface SyncEvent extends ExtendableEvent {
|
|
40
|
-
readonly lastChance: boolean;
|
|
41
|
-
readonly tag: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface ServiceWorkerGlobalScopeEventMap {
|
|
45
|
-
sync: SyncEvent;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export {
|
|
50
|
-
// Background synchronization
|
|
51
|
-
BackgroundSyncPlugin,
|
|
52
|
-
BackgroundSyncQueue,
|
|
53
|
-
BackgroundSyncQueueStore,
|
|
54
|
-
StorableRequest,
|
|
55
|
-
// Update broadcasting
|
|
56
|
-
BroadcastCacheUpdate,
|
|
57
|
-
BroadcastUpdatePlugin,
|
|
58
|
-
responsesAreSame,
|
|
59
|
-
BROADCAST_UPDATE_MESSAGE_META,
|
|
60
|
-
BROADCAST_UPDATE_MESSAGE_TYPE,
|
|
61
|
-
BROADCAST_UPDATE_DEFAULT_HEADERS,
|
|
62
|
-
// Cacheable responses
|
|
63
|
-
CacheableResponse,
|
|
64
|
-
CacheableResponsePlugin,
|
|
65
|
-
// Expiration
|
|
66
|
-
CacheExpiration,
|
|
67
|
-
ExpirationPlugin,
|
|
68
|
-
// Precaching
|
|
69
|
-
PrecacheFallbackPlugin,
|
|
70
|
-
// Range requests
|
|
71
|
-
createPartialResponse,
|
|
72
|
-
RangeRequestsPlugin,
|
|
73
|
-
// Google Analytics
|
|
74
|
-
initializeGoogleAnalytics,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export type {
|
|
78
|
-
// Background synchronization
|
|
79
|
-
BackgroundSyncQueueOptions,
|
|
80
|
-
BackgroundSyncQueueEntry,
|
|
81
|
-
// Update broadcasting
|
|
82
|
-
BroadcastCacheUpdateOptions,
|
|
83
|
-
BroadcastPayload,
|
|
84
|
-
BroadcastPayloadGenerator,
|
|
85
|
-
BroadcastMessage,
|
|
86
|
-
// Cacheable responses
|
|
87
|
-
CacheableResponseOptions,
|
|
88
|
-
// Expiration
|
|
89
|
-
ExpirationPluginOptions,
|
|
90
|
-
// Precaching
|
|
91
|
-
PrecacheFallbackEntry,
|
|
92
|
-
PrecacheFallbackPluginOptions,
|
|
93
|
-
// Google Analytics
|
|
94
|
-
GoogleAnalyticsInitializeOptions,
|
|
95
|
-
};
|
package/src/index.precaching.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { PrecacheController } from "./precaching/PrecacheController.js";
|
|
2
|
-
import { PrecacheRoute } from "./precaching/PrecacheRoute.js";
|
|
3
|
-
import { PrecacheStrategy } from "./precaching/PrecacheStrategy.js";
|
|
4
|
-
import { addPlugins } from "./precaching/addPlugins.js";
|
|
5
|
-
import { addRoute } from "./precaching/addRoute.js";
|
|
6
|
-
import { cleanupOutdatedCaches } from "./precaching/cleanupOutdatedCaches.js";
|
|
7
|
-
import { createHandlerBoundToURL } from "./precaching/createHandlerBoundToURL.js";
|
|
8
|
-
import { getCacheKeyForURL } from "./precaching/getCacheKeyForURL.js";
|
|
9
|
-
import { matchPrecache } from "./precaching/matchPrecache.js";
|
|
10
|
-
import { precache } from "./precaching/precache.js";
|
|
11
|
-
import { precacheAndRoute } from "./precaching/precacheAndRoute.js";
|
|
12
|
-
import { getSingletonPrecacheController, setSingletonPrecacheController } from "./precaching/singletonPrecacheController.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Most consumers of this module will want to use the
|
|
16
|
-
* `@serwist/sw/precaching.precacheAndRoute`
|
|
17
|
-
* method to add assets to the cache and respond to network requests with these
|
|
18
|
-
* cached assets.
|
|
19
|
-
*
|
|
20
|
-
* If you require more control over caching and routing, you can use the
|
|
21
|
-
* `@serwist/precaching.PrecacheController`
|
|
22
|
-
* interface.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
addPlugins,
|
|
27
|
-
addRoute,
|
|
28
|
-
cleanupOutdatedCaches,
|
|
29
|
-
createHandlerBoundToURL,
|
|
30
|
-
getCacheKeyForURL,
|
|
31
|
-
matchPrecache,
|
|
32
|
-
precache,
|
|
33
|
-
precacheAndRoute,
|
|
34
|
-
PrecacheController,
|
|
35
|
-
PrecacheRoute,
|
|
36
|
-
PrecacheStrategy,
|
|
37
|
-
getSingletonPrecacheController,
|
|
38
|
-
setSingletonPrecacheController,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type * from "./precaching/types.js";
|
package/src/index.routing.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { NavigationRouteMatchOptions } from "./routing/NavigationRoute.js";
|
|
2
|
-
import { NavigationRoute } from "./routing/NavigationRoute.js";
|
|
3
|
-
import { RegExpRoute } from "./routing/RegExpRoute.js";
|
|
4
|
-
import { Route } from "./routing/Route.js";
|
|
5
|
-
import { Router } from "./routing/Router.js";
|
|
6
|
-
import { parseRoute } from "./routing/parseRoute.js";
|
|
7
|
-
import { registerRoute } from "./routing/registerRoute.js";
|
|
8
|
-
import { setCatchHandler } from "./routing/setCatchHandler.js";
|
|
9
|
-
import { setDefaultHandler } from "./routing/setDefaultHandler.js";
|
|
10
|
-
import { getSingletonRouter, setSingletonRouter } from "./routing/singletonRouter.js";
|
|
11
|
-
import { unregisterRoute } from "./routing/unregisterRoute.js";
|
|
12
|
-
import type { HTTPMethod } from "./routing/utils/constants.js";
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
NavigationRoute,
|
|
16
|
-
RegExpRoute,
|
|
17
|
-
parseRoute,
|
|
18
|
-
registerRoute,
|
|
19
|
-
Route,
|
|
20
|
-
Router,
|
|
21
|
-
setCatchHandler,
|
|
22
|
-
setDefaultHandler,
|
|
23
|
-
getSingletonRouter,
|
|
24
|
-
setSingletonRouter,
|
|
25
|
-
unregisterRoute,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type { HTTPMethod, NavigationRouteMatchOptions };
|
package/src/index.strategies.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CacheFirst } from "./strategies/CacheFirst.js";
|
|
2
|
-
import { CacheOnly } from "./strategies/CacheOnly.js";
|
|
3
|
-
import type { NetworkFirstOptions } from "./strategies/NetworkFirst.js";
|
|
4
|
-
import { NetworkFirst } from "./strategies/NetworkFirst.js";
|
|
5
|
-
import type { NetworkOnlyOptions } from "./strategies/NetworkOnly.js";
|
|
6
|
-
import { NetworkOnly } from "./strategies/NetworkOnly.js";
|
|
7
|
-
import { StaleWhileRevalidate } from "./strategies/StaleWhileRevalidate.js";
|
|
8
|
-
import type { StrategyOptions } from "./strategies/Strategy.js";
|
|
9
|
-
import { Strategy } from "./strategies/Strategy.js";
|
|
10
|
-
import { StrategyHandler } from "./strategies/StrategyHandler.js";
|
|
11
|
-
|
|
12
|
-
// See https://github.com/GoogleChrome/workbox/issues/2946
|
|
13
|
-
declare global {
|
|
14
|
-
interface FetchEvent {
|
|
15
|
-
// See https://github.com/GoogleChrome/workbox/issues/2974
|
|
16
|
-
readonly preloadResponse: Promise<any>;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* There are common caching strategies that most service workers will need
|
|
22
|
-
* and use. This module provides simple implementations of these strategies.
|
|
23
|
-
*/
|
|
24
|
-
export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate, Strategy, StrategyHandler };
|
|
25
|
-
|
|
26
|
-
export type { NetworkFirstOptions, NetworkOnlyOptions, StrategyOptions };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { FetchDidFailCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
10
|
-
|
|
11
|
-
import type { QueueOptions } from "./Queue.js";
|
|
12
|
-
import { Queue } from "./Queue.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A class implementing the `fetchDidFail` lifecycle callback. This makes it
|
|
16
|
-
* easier to add failed requests to a background sync Queue.
|
|
17
|
-
*/
|
|
18
|
-
export class BackgroundSyncPlugin implements SerwistPlugin {
|
|
19
|
-
private readonly _queue: Queue;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param name See the `@serwist/sw/plugins.BackgroundSyncQueue`
|
|
23
|
-
* documentation for parameter details.
|
|
24
|
-
* @param options See the `@serwist/sw/plugins.BackgroundSyncQueue`
|
|
25
|
-
* documentation for parameter details.
|
|
26
|
-
* @see https://serwist.pages.dev/docs/background-sync/queue
|
|
27
|
-
*/
|
|
28
|
-
constructor(name: string, options?: QueueOptions) {
|
|
29
|
-
this._queue = new Queue(name, options);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param options
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
async fetchDidFail({ request }: FetchDidFailCallbackParam) {
|
|
37
|
-
await this._queue.pushRequest({ request });
|
|
38
|
-
}
|
|
39
|
-
}
|