@serwist/sw 9.0.0-preview.18 → 9.0.0-preview.19

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.
@@ -1 +1 @@
1
- {"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../../src/abstractions/Serwist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gCAAgC,EAAc,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAMzE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAK9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC;IACpE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC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AC;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC;IACpE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;CACtD;AAED,qBAAa,OAAO;IAClB,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,OAAO,CAAS;gBACZ,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAE,cAAmB;IAI/D,OAAO,CAAC,EACN,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,WAAmB,EACnB,aAAa,EACb,iBAAyB,EACzB,OAAO,EACP,YAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,cAAsB,EACtB,SAAS,GACV,EAAE,qBAAqB;CA8DzB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checks whether the current browser supports
3
+ * navigation preloading.
4
+ *
5
+ * @returns
6
+ */
7
+ export declare const isNavigationPreloadSupported: () => boolean;
8
+ /**
9
+ * If the browser supports navigation preloading, then this will enable it.
10
+ *
11
+ * @param headerValue Optional. Allows developers to override the value of
12
+ * the `Service-Worker-Navigation-Preload` header which will be sent to the
13
+ * server when making the navigation request.
14
+ */
15
+ export declare const enableNavigationPreload: (headerValue?: string) => void;
16
+ /**
17
+ * If the browser supports navigation preloading, then this will disable it.
18
+ */
19
+ export declare const disableNavigationPreload: () => void;
20
+ //# sourceMappingURL=navigationPreload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigationPreload.d.ts","sourceRoot":"","sources":["../../src/abstractions/navigationPreload.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAO,OAE/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,iBAAkB,MAAM,KAAG,IAqB9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAAO,IAgB3C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,8 +4,9 @@ import type { FallbackEntry, FallbackMatcher, FallbacksOptions } from "./abstrac
4
4
  import { fallbacks } from "./abstractions/fallbacks.js";
5
5
  import { type HandlePrecachingOptions, handlePrecaching } from "./abstractions/handlePrecaching.js";
6
6
  import { type InstallSerwistOptions, installSerwist } from "./abstractions/installSerwist.js";
7
+ import { disableNavigationPreload, enableNavigationPreload, isNavigationPreloadSupported } from "./abstractions/navigationPreload.js";
7
8
  import { registerRuntimeCaching } from "./abstractions/registerRuntimeCaching.js";
8
9
  import type { RuntimeCaching } from "./abstractions/types.js";
9
- export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, Serwist, registerRuntimeCaching };
10
+ export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, Serwist, registerRuntimeCaching, disableNavigationPreload, enableNavigationPreload, isNavigationPreloadSupported, };
10
11
  export type { FallbackEntry, FallbackMatcher, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions, SerwistOptions, SerwistInstallOptions, RuntimeCaching, };
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,KAAK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wB,EACxB,uBAAuB,EACvB,4BAA4B,GAC7B,CAAC;AACF,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,cAAc,EACd,qBAAqB,EACrB,cAAc,GACf,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { setCacheNameDetails, clientsClaim } from '@serwist/core';
2
- import { enable } from '@serwist/navigation-preload';
3
2
  import { P as PrecacheFallbackPlugin, i as initialize } from './chunks/PrecacheFallbackPlugin.js';
4
3
  import { p as precacheAndRoute, P as PrecacheRoute, c as cleanupOutdatedCaches, a as createHandlerBoundToURL } from './chunks/precacheAndRoute.js';
5
4
  import { g as getOrCreatePrecacheController } from './chunks/getOrCreatePrecacheController.js';
@@ -28,6 +27,43 @@ const fallbacks = ({ runtimeCaching, entries, precacheOptions })=>{
28
27
  return runtimeCaching;
29
28
  };
30
29
 
30
+ const isNavigationPreloadSupported = ()=>{
31
+ return Boolean(self.registration?.navigationPreload);
32
+ };
33
+ const enableNavigationPreload = (headerValue)=>{
34
+ if (isNavigationPreloadSupported()) {
35
+ self.addEventListener("activate", (event)=>{
36
+ event.waitUntil(self.registration.navigationPreload.enable().then(()=>{
37
+ if (headerValue) {
38
+ void self.registration.navigationPreload.setHeaderValue(headerValue);
39
+ }
40
+ if (process.env.NODE_ENV !== "production") {
41
+ logger.log("Navigation preloading is enabled.");
42
+ }
43
+ }));
44
+ });
45
+ } else {
46
+ if (process.env.NODE_ENV !== "production") {
47
+ logger.log("Navigation preloading is not supported in this browser.");
48
+ }
49
+ }
50
+ };
51
+ const disableNavigationPreload = ()=>{
52
+ if (isNavigationPreloadSupported()) {
53
+ self.addEventListener("activate", (event)=>{
54
+ event.waitUntil(self.registration.navigationPreload.disable().then(()=>{
55
+ if (process.env.NODE_ENV !== "production") {
56
+ logger.log("Navigation preloading is disabled.");
57
+ }
58
+ }));
59
+ });
60
+ } else {
61
+ if (process.env.NODE_ENV !== "production") {
62
+ logger.log("Navigation preloading is not supported in this browser.");
63
+ }
64
+ }
65
+ };
66
+
31
67
  class Serwist {
32
68
  _precacheController;
33
69
  _router;
@@ -37,7 +73,7 @@ class Serwist {
37
73
  }
38
74
  install({ precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist, skipWaiting = false, importScripts, navigationPreload = false, cacheId, clientsClaim: clientsClaim$1 = false, runtimeCaching, offlineAnalyticsConfig, disableDevLogs: disableDevLogs$1 = false, fallbacks: fallbacks$1 }) {
39
75
  if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
40
- if (navigationPreload) enable();
76
+ if (navigationPreload) enableNavigationPreload();
41
77
  if (cacheId !== undefined) {
42
78
  setCacheNameDetails({
43
79
  prefix: cacheId
@@ -116,4 +152,4 @@ const registerRuntimeCaching = (...runtimeCachingList)=>{
116
152
  }
117
153
  };
118
154
 
119
- export { Serwist, disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
155
+ export { Serwist, disableDevLogs, disableNavigationPreload, enableNavigationPreload, fallbacks, handlePrecaching, installSerwist, isNavigationPreloadSupported, registerRuntimeCaching };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@serwist/sw",
3
- "version": "9.0.0-preview.18",
3
+ "version": "9.0.0-preview.19",
4
4
  "type": "module",
5
- "description": "A module that makes it easy to get started with the Serwist service worker libraries.",
5
+ "description": "A service worker helper module.",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -15,8 +15,8 @@
15
15
  ],
16
16
  "author": "Google's Web DevRel Team, Serwist's Team",
17
17
  "license": "MIT",
18
- "repository": "serwist/serwist",
19
- "bugs": "https://github.com/serwist/serwist/issues",
18
+ "repository": "https://gitlab.com/serwist/serwist",
19
+ "bugs": "https://gitlab.com/serwist/serwist/issues",
20
20
  "homepage": "https://serwist.pages.dev",
21
21
  "main": "./dist/index.js",
22
22
  "types": "./dist/index.d.ts",
@@ -61,14 +61,13 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "idb": "8.0.0",
64
- "@serwist/core": "9.0.0-preview.18",
65
- "@serwist/navigation-preload": "9.0.0-preview.18"
64
+ "@serwist/core": "9.0.0-preview.19"
66
65
  },
67
66
  "devDependencies": {
68
67
  "rollup": "4.13.0",
69
68
  "typescript": "5.5.0-dev.20240323",
70
- "@serwist/utils": "9.0.0-preview.18",
71
- "@serwist/constants": "9.0.0-preview.18"
69
+ "@serwist/constants": "9.0.0-preview.19",
70
+ "@serwist/utils": "9.0.0-preview.19"
72
71
  },
73
72
  "peerDependencies": {
74
73
  "typescript": ">=5.0.0"
@@ -1,5 +1,4 @@
1
1
  import { clientsClaim as clientsClaimImpl, setCacheNameDetails } from "@serwist/core";
2
- import { enable } from "@serwist/navigation-preload";
3
2
  import { type GoogleAnalyticsInitializeOptions, initialize } from "../plugins/googleAnalytics/initialize.js";
4
3
  import { PrecacheController } from "../precaching/PrecacheController.js";
5
4
  import { PrecacheRoute } from "../precaching/PrecacheRoute.js";
@@ -14,6 +13,7 @@ import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
14
13
  import { fallbacks as fallbacksImpl } from "./fallbacks.js";
15
14
  import type { FallbacksOptions } from "./fallbacks.js";
16
15
  import { type HandlePrecachingOptions } from "./handlePrecaching.js";
16
+ import { enableNavigationPreload } from "./navigationPreload.js";
17
17
  import type { RuntimeCaching } from "./types.js";
18
18
 
19
19
  declare const self: ServiceWorkerGlobalScope;
@@ -117,7 +117,7 @@ export class Serwist {
117
117
  }: SerwistInstallOptions) {
118
118
  if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
119
119
 
120
- if (navigationPreload) enable();
120
+ if (navigationPreload) enableNavigationPreload();
121
121
 
122
122
  if (cacheId !== undefined) {
123
123
  setCacheNameDetails({
@@ -0,0 +1,64 @@
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
+ };
package/src/index.ts CHANGED
@@ -4,10 +4,22 @@ import type { FallbackEntry, FallbackMatcher, FallbacksOptions } from "./abstrac
4
4
  import { fallbacks } from "./abstractions/fallbacks.js";
5
5
  import { type HandlePrecachingOptions, handlePrecaching } from "./abstractions/handlePrecaching.js";
6
6
  import { type InstallSerwistOptions, installSerwist } from "./abstractions/installSerwist.js";
7
+ import { disableNavigationPreload, enableNavigationPreload, isNavigationPreloadSupported } from "./abstractions/navigationPreload.js";
7
8
  import { registerRuntimeCaching } from "./abstractions/registerRuntimeCaching.js";
8
9
  import type { RuntimeCaching } from "./abstractions/types.js";
9
10
 
10
- export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, Serwist, registerRuntimeCaching };
11
+ export {
12
+ disableDevLogs,
13
+ fallbacks,
14
+ handlePrecaching,
15
+ installSerwist,
16
+ Serwist,
17
+ registerRuntimeCaching,
18
+ // Navigation preloading
19
+ disableNavigationPreload,
20
+ enableNavigationPreload,
21
+ isNavigationPreloadSupported,
22
+ };
11
23
  export type {
12
24
  FallbackEntry,
13
25
  FallbackMatcher,