@tramvai/pwa-recipes 2.121.2
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/lib/cache-application-fonts.d.ts +5 -0
- package/lib/cache-application-fonts.es.js +32 -0
- package/lib/cache-application-fonts.js +36 -0
- package/lib/cache-application-images.d.ts +5 -0
- package/lib/cache-application-images.es.js +32 -0
- package/lib/cache-application-images.js +36 -0
- package/lib/cache-application-pages.d.ts +7 -0
- package/lib/cache-application-pages.es.js +34 -0
- package/lib/cache-application-pages.js +38 -0
- package/lib/cache-application-static-assets.d.ts +5 -0
- package/lib/cache-application-static-assets.es.js +34 -0
- package/lib/cache-application-static-assets.js +38 -0
- package/lib/cache.d.ts +1 -0
- package/lib/cache.es.js +3 -0
- package/lib/cache.js +7 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.es.js +7 -0
- package/lib/index.js +23 -0
- package/lib/routing.d.ts +2 -0
- package/lib/routing.es.js +6 -0
- package/lib/routing.js +11 -0
- package/lib/types.d.ts +17 -0
- package/lib/warm-strategy-cache.d.ts +6 -0
- package/lib/warm-strategy-cache.es.js +54 -0
- package/lib/warm-strategy-cache.js +59 -0
- package/package.json +31 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ApplicationAssetsCacheOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/googleFontsCache.ts
|
|
4
|
+
*/
|
|
5
|
+
export declare function cacheApplicationFonts({ precacheManifest, maxEntries, maxAgeSeconds, strategy: Strategy, }?: ApplicationAssetsCacheOptions): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Route, registerRoute } from 'workbox-routing';
|
|
2
|
+
import { StaleWhileRevalidate } from 'workbox-strategies';
|
|
3
|
+
import { ExpirationPlugin } from 'workbox-expiration';
|
|
4
|
+
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
|
5
|
+
import { warmStrategyCache } from './warm-strategy-cache.es.js';
|
|
6
|
+
import { isApplicationAsset } from './routing.es.js';
|
|
7
|
+
import { createCacheKey } from './cache.es.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/googleFontsCache.ts
|
|
11
|
+
*/
|
|
12
|
+
function cacheApplicationFonts({ precacheManifest = [], maxEntries = 30, maxAgeSeconds = 90 * 24 * 60 * 60, strategy: Strategy = StaleWhileRevalidate, } = {}) {
|
|
13
|
+
const strategy = new Strategy({
|
|
14
|
+
cacheName: createCacheKey('fonts'),
|
|
15
|
+
plugins: [
|
|
16
|
+
new CacheableResponsePlugin({
|
|
17
|
+
statuses: [0, 200],
|
|
18
|
+
}),
|
|
19
|
+
new ExpirationPlugin({
|
|
20
|
+
maxEntries,
|
|
21
|
+
maxAgeSeconds,
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const route = new Route(({ request }) => {
|
|
26
|
+
return isApplicationAsset(request) && request.destination === 'font';
|
|
27
|
+
}, strategy);
|
|
28
|
+
warmStrategyCache({ urls: precacheManifest, type: 'font', strategy });
|
|
29
|
+
registerRoute(route);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { cacheApplicationFonts };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var workboxRouting = require('workbox-routing');
|
|
6
|
+
var workboxStrategies = require('workbox-strategies');
|
|
7
|
+
var workboxExpiration = require('workbox-expiration');
|
|
8
|
+
var workboxCacheableResponse = require('workbox-cacheable-response');
|
|
9
|
+
var warmStrategyCache = require('./warm-strategy-cache.js');
|
|
10
|
+
var routing = require('./routing.js');
|
|
11
|
+
var cache = require('./cache.js');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/googleFontsCache.ts
|
|
15
|
+
*/
|
|
16
|
+
function cacheApplicationFonts({ precacheManifest = [], maxEntries = 30, maxAgeSeconds = 90 * 24 * 60 * 60, strategy: Strategy = workboxStrategies.StaleWhileRevalidate, } = {}) {
|
|
17
|
+
const strategy = new Strategy({
|
|
18
|
+
cacheName: cache.createCacheKey('fonts'),
|
|
19
|
+
plugins: [
|
|
20
|
+
new workboxCacheableResponse.CacheableResponsePlugin({
|
|
21
|
+
statuses: [0, 200],
|
|
22
|
+
}),
|
|
23
|
+
new workboxExpiration.ExpirationPlugin({
|
|
24
|
+
maxEntries,
|
|
25
|
+
maxAgeSeconds,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
const route = new workboxRouting.Route(({ request }) => {
|
|
30
|
+
return routing.isApplicationAsset(request) && request.destination === 'font';
|
|
31
|
+
}, strategy);
|
|
32
|
+
warmStrategyCache.warmStrategyCache({ urls: precacheManifest, type: 'font', strategy });
|
|
33
|
+
workboxRouting.registerRoute(route);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.cacheApplicationFonts = cacheApplicationFonts;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ApplicationAssetsCacheOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/imageCache.ts
|
|
4
|
+
*/
|
|
5
|
+
export declare function cacheApplicationImages({ precacheManifest, maxEntries, maxAgeSeconds, strategy: Strategy, }?: ApplicationAssetsCacheOptions): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Route, registerRoute } from 'workbox-routing';
|
|
2
|
+
import { StaleWhileRevalidate } from 'workbox-strategies';
|
|
3
|
+
import { ExpirationPlugin } from 'workbox-expiration';
|
|
4
|
+
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
|
5
|
+
import { warmStrategyCache } from './warm-strategy-cache.es.js';
|
|
6
|
+
import { isApplicationAsset } from './routing.es.js';
|
|
7
|
+
import { createCacheKey } from './cache.es.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/imageCache.ts
|
|
11
|
+
*/
|
|
12
|
+
function cacheApplicationImages({ precacheManifest = [], maxEntries = 60, maxAgeSeconds = 30 * 24 * 60 * 60, strategy: Strategy = StaleWhileRevalidate, } = {}) {
|
|
13
|
+
const strategy = new Strategy({
|
|
14
|
+
cacheName: createCacheKey('images'),
|
|
15
|
+
plugins: [
|
|
16
|
+
new CacheableResponsePlugin({
|
|
17
|
+
statuses: [0, 200],
|
|
18
|
+
}),
|
|
19
|
+
new ExpirationPlugin({
|
|
20
|
+
maxEntries,
|
|
21
|
+
maxAgeSeconds,
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const route = new Route(({ request }) => {
|
|
26
|
+
return isApplicationAsset(request) && request.destination === 'image';
|
|
27
|
+
}, strategy);
|
|
28
|
+
warmStrategyCache({ urls: precacheManifest, type: 'image', strategy });
|
|
29
|
+
registerRoute(route);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { cacheApplicationImages };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var workboxRouting = require('workbox-routing');
|
|
6
|
+
var workboxStrategies = require('workbox-strategies');
|
|
7
|
+
var workboxExpiration = require('workbox-expiration');
|
|
8
|
+
var workboxCacheableResponse = require('workbox-cacheable-response');
|
|
9
|
+
var warmStrategyCache = require('./warm-strategy-cache.js');
|
|
10
|
+
var routing = require('./routing.js');
|
|
11
|
+
var cache = require('./cache.js');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/imageCache.ts
|
|
15
|
+
*/
|
|
16
|
+
function cacheApplicationImages({ precacheManifest = [], maxEntries = 60, maxAgeSeconds = 30 * 24 * 60 * 60, strategy: Strategy = workboxStrategies.StaleWhileRevalidate, } = {}) {
|
|
17
|
+
const strategy = new Strategy({
|
|
18
|
+
cacheName: cache.createCacheKey('images'),
|
|
19
|
+
plugins: [
|
|
20
|
+
new workboxCacheableResponse.CacheableResponsePlugin({
|
|
21
|
+
statuses: [0, 200],
|
|
22
|
+
}),
|
|
23
|
+
new workboxExpiration.ExpirationPlugin({
|
|
24
|
+
maxEntries,
|
|
25
|
+
maxAgeSeconds,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
const route = new workboxRouting.Route(({ request }) => {
|
|
30
|
+
return routing.isApplicationAsset(request) && request.destination === 'image';
|
|
31
|
+
}, strategy);
|
|
32
|
+
warmStrategyCache.warmStrategyCache({ urls: precacheManifest, type: 'image', strategy });
|
|
33
|
+
workboxRouting.registerRoute(route);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.cacheApplicationImages = cacheApplicationImages;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApplicationAssetsCacheOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/pageCache.ts
|
|
4
|
+
*/
|
|
5
|
+
export declare function cacheApplicationPages({ precacheManifest, maxEntries, maxAgeSeconds, networkTimeoutSeconds, strategy: Strategy, }?: ApplicationAssetsCacheOptions & {
|
|
6
|
+
networkTimeoutSeconds?: number;
|
|
7
|
+
}): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Route, registerRoute } from 'workbox-routing';
|
|
2
|
+
import { NetworkFirst } from 'workbox-strategies';
|
|
3
|
+
import { ExpirationPlugin } from 'workbox-expiration';
|
|
4
|
+
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
|
5
|
+
import { warmStrategyCache } from './warm-strategy-cache.es.js';
|
|
6
|
+
import { isApplicationScope } from './routing.es.js';
|
|
7
|
+
import { createCacheKey } from './cache.es.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/pageCache.ts
|
|
11
|
+
*/
|
|
12
|
+
function cacheApplicationPages({ precacheManifest = [], maxEntries = 30, maxAgeSeconds = 30 * 24 * 60 * 60, networkTimeoutSeconds = 3, strategy: Strategy = NetworkFirst, } = {}) {
|
|
13
|
+
const strategy = new Strategy({
|
|
14
|
+
cacheName: createCacheKey('pages'),
|
|
15
|
+
networkTimeoutSeconds,
|
|
16
|
+
plugins: [
|
|
17
|
+
new CacheableResponsePlugin({
|
|
18
|
+
statuses: [0, 200],
|
|
19
|
+
}),
|
|
20
|
+
new ExpirationPlugin({
|
|
21
|
+
maxEntries,
|
|
22
|
+
maxAgeSeconds,
|
|
23
|
+
purgeOnQuotaError: true,
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
const route = new Route(({ request }) => {
|
|
28
|
+
return isApplicationScope(request) && request.mode === 'navigate';
|
|
29
|
+
}, strategy);
|
|
30
|
+
warmStrategyCache({ urls: precacheManifest, type: 'html', strategy });
|
|
31
|
+
registerRoute(route);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { cacheApplicationPages };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var workboxRouting = require('workbox-routing');
|
|
6
|
+
var workboxStrategies = require('workbox-strategies');
|
|
7
|
+
var workboxExpiration = require('workbox-expiration');
|
|
8
|
+
var workboxCacheableResponse = require('workbox-cacheable-response');
|
|
9
|
+
var warmStrategyCache = require('./warm-strategy-cache.js');
|
|
10
|
+
var routing = require('./routing.js');
|
|
11
|
+
var cache = require('./cache.js');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/pageCache.ts
|
|
15
|
+
*/
|
|
16
|
+
function cacheApplicationPages({ precacheManifest = [], maxEntries = 30, maxAgeSeconds = 30 * 24 * 60 * 60, networkTimeoutSeconds = 3, strategy: Strategy = workboxStrategies.NetworkFirst, } = {}) {
|
|
17
|
+
const strategy = new Strategy({
|
|
18
|
+
cacheName: cache.createCacheKey('pages'),
|
|
19
|
+
networkTimeoutSeconds,
|
|
20
|
+
plugins: [
|
|
21
|
+
new workboxCacheableResponse.CacheableResponsePlugin({
|
|
22
|
+
statuses: [0, 200],
|
|
23
|
+
}),
|
|
24
|
+
new workboxExpiration.ExpirationPlugin({
|
|
25
|
+
maxEntries,
|
|
26
|
+
maxAgeSeconds,
|
|
27
|
+
purgeOnQuotaError: true,
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
});
|
|
31
|
+
const route = new workboxRouting.Route(({ request }) => {
|
|
32
|
+
return routing.isApplicationScope(request) && request.mode === 'navigate';
|
|
33
|
+
}, strategy);
|
|
34
|
+
warmStrategyCache.warmStrategyCache({ urls: precacheManifest, type: 'html', strategy });
|
|
35
|
+
workboxRouting.registerRoute(route);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.cacheApplicationPages = cacheApplicationPages;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ApplicationAssetsCacheOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/staticResourceCache.ts
|
|
4
|
+
*/
|
|
5
|
+
export declare function cacheApplicationStaticAssets({ precacheManifest, maxEntries, maxAgeSeconds, strategy: Strategy, }?: ApplicationAssetsCacheOptions): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Route, registerRoute } from 'workbox-routing';
|
|
2
|
+
import { StaleWhileRevalidate } from 'workbox-strategies';
|
|
3
|
+
import { ExpirationPlugin } from 'workbox-expiration';
|
|
4
|
+
import { CacheableResponsePlugin } from 'workbox-cacheable-response';
|
|
5
|
+
import { warmStrategyCache } from './warm-strategy-cache.es.js';
|
|
6
|
+
import { isApplicationAsset, isApplicationScope } from './routing.es.js';
|
|
7
|
+
import { createCacheKey } from './cache.es.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/staticResourceCache.ts
|
|
11
|
+
*/
|
|
12
|
+
function cacheApplicationStaticAssets({ precacheManifest = [], maxEntries = 60, maxAgeSeconds, strategy: Strategy = StaleWhileRevalidate, } = {}) {
|
|
13
|
+
const strategy = new Strategy({
|
|
14
|
+
cacheName: createCacheKey('static-assets'),
|
|
15
|
+
plugins: [
|
|
16
|
+
new CacheableResponsePlugin({
|
|
17
|
+
statuses: [0, 200],
|
|
18
|
+
}),
|
|
19
|
+
new ExpirationPlugin({
|
|
20
|
+
maxEntries,
|
|
21
|
+
maxAgeSeconds,
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const route = new Route(({ request }) => {
|
|
26
|
+
return ((isApplicationAsset(request) &&
|
|
27
|
+
(request.destination === 'script' || request.destination === 'style')) ||
|
|
28
|
+
(isApplicationScope(request) && request.destination === 'manifest'));
|
|
29
|
+
}, strategy);
|
|
30
|
+
warmStrategyCache({ urls: precacheManifest, type: ['script', 'style', 'manifest'], strategy });
|
|
31
|
+
registerRoute(route);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { cacheApplicationStaticAssets };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var workboxRouting = require('workbox-routing');
|
|
6
|
+
var workboxStrategies = require('workbox-strategies');
|
|
7
|
+
var workboxExpiration = require('workbox-expiration');
|
|
8
|
+
var workboxCacheableResponse = require('workbox-cacheable-response');
|
|
9
|
+
var warmStrategyCache = require('./warm-strategy-cache.js');
|
|
10
|
+
var routing = require('./routing.js');
|
|
11
|
+
var cache = require('./cache.js');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/staticResourceCache.ts
|
|
15
|
+
*/
|
|
16
|
+
function cacheApplicationStaticAssets({ precacheManifest = [], maxEntries = 60, maxAgeSeconds, strategy: Strategy = workboxStrategies.StaleWhileRevalidate, } = {}) {
|
|
17
|
+
const strategy = new Strategy({
|
|
18
|
+
cacheName: cache.createCacheKey('static-assets'),
|
|
19
|
+
plugins: [
|
|
20
|
+
new workboxCacheableResponse.CacheableResponsePlugin({
|
|
21
|
+
statuses: [0, 200],
|
|
22
|
+
}),
|
|
23
|
+
new workboxExpiration.ExpirationPlugin({
|
|
24
|
+
maxEntries,
|
|
25
|
+
maxAgeSeconds,
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
const route = new workboxRouting.Route(({ request }) => {
|
|
30
|
+
return ((routing.isApplicationAsset(request) &&
|
|
31
|
+
(request.destination === 'script' || request.destination === 'style')) ||
|
|
32
|
+
(routing.isApplicationScope(request) && request.destination === 'manifest'));
|
|
33
|
+
}, strategy);
|
|
34
|
+
warmStrategyCache.warmStrategyCache({ urls: precacheManifest, type: ['script', 'style', 'manifest'], strategy });
|
|
35
|
+
workboxRouting.registerRoute(route);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.cacheApplicationStaticAssets = cacheApplicationStaticAssets;
|
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createCacheKey: (key: string) => string;
|
package/lib/cache.es.js
ADDED
package/lib/cache.js
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './cache';
|
|
3
|
+
export * from './routing';
|
|
4
|
+
export * from './warm-strategy-cache';
|
|
5
|
+
export * from './cache-application-static-assets';
|
|
6
|
+
export * from './cache-application-images';
|
|
7
|
+
export * from './cache-application-fonts';
|
|
8
|
+
export * from './cache-application-pages';
|
package/lib/index.es.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createCacheKey } from './cache.es.js';
|
|
2
|
+
export { isApplicationAsset, isApplicationScope } from './routing.es.js';
|
|
3
|
+
export { matchResourceType, warmStrategyCache } from './warm-strategy-cache.es.js';
|
|
4
|
+
export { cacheApplicationStaticAssets } from './cache-application-static-assets.es.js';
|
|
5
|
+
export { cacheApplicationImages } from './cache-application-images.es.js';
|
|
6
|
+
export { cacheApplicationFonts } from './cache-application-fonts.es.js';
|
|
7
|
+
export { cacheApplicationPages } from './cache-application-pages.es.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var cache = require('./cache.js');
|
|
6
|
+
var routing = require('./routing.js');
|
|
7
|
+
var warmStrategyCache = require('./warm-strategy-cache.js');
|
|
8
|
+
var cacheApplicationStaticAssets = require('./cache-application-static-assets.js');
|
|
9
|
+
var cacheApplicationImages = require('./cache-application-images.js');
|
|
10
|
+
var cacheApplicationFonts = require('./cache-application-fonts.js');
|
|
11
|
+
var cacheApplicationPages = require('./cache-application-pages.js');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.createCacheKey = cache.createCacheKey;
|
|
16
|
+
exports.isApplicationAsset = routing.isApplicationAsset;
|
|
17
|
+
exports.isApplicationScope = routing.isApplicationScope;
|
|
18
|
+
exports.matchResourceType = warmStrategyCache.matchResourceType;
|
|
19
|
+
exports.warmStrategyCache = warmStrategyCache.warmStrategyCache;
|
|
20
|
+
exports.cacheApplicationStaticAssets = cacheApplicationStaticAssets.cacheApplicationStaticAssets;
|
|
21
|
+
exports.cacheApplicationImages = cacheApplicationImages.cacheApplicationImages;
|
|
22
|
+
exports.cacheApplicationFonts = cacheApplicationFonts.cacheApplicationFonts;
|
|
23
|
+
exports.cacheApplicationPages = cacheApplicationPages.cacheApplicationPages;
|
package/lib/routing.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const isApplicationAsset = (request) => request.url.startsWith(process.env.ASSETS_PREFIX);
|
|
2
|
+
const isApplicationScope = (request) => {
|
|
3
|
+
return new URL(request.url).pathname.startsWith(process.env.TRAMVAI_PWA_SW_SCOPE);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export { isApplicationAsset, isApplicationScope };
|
package/lib/routing.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const isApplicationAsset = (request) => request.url.startsWith(process.env.ASSETS_PREFIX);
|
|
6
|
+
const isApplicationScope = (request) => {
|
|
7
|
+
return new URL(request.url).pathname.startsWith(process.env.TRAMVAI_PWA_SW_SCOPE);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.isApplicationAsset = isApplicationAsset;
|
|
11
|
+
exports.isApplicationScope = isApplicationScope;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PrecacheEntry } from 'workbox-precaching';
|
|
2
|
+
import type { Strategy, StrategyOptions } from 'workbox-strategies';
|
|
3
|
+
export interface ApplicationAssetsCacheOptions {
|
|
4
|
+
precacheManifest?: Array<string | PrecacheEntry>;
|
|
5
|
+
maxEntries?: number;
|
|
6
|
+
maxAgeSeconds?: number;
|
|
7
|
+
strategy?: StrategyConstructor;
|
|
8
|
+
}
|
|
9
|
+
export interface StrategyConstructor {
|
|
10
|
+
new (options: StrategyOptions & Record<string, any>): Strategy;
|
|
11
|
+
}
|
|
12
|
+
export interface WarmStrategyCacheOptions {
|
|
13
|
+
urls: Array<string | PrecacheEntry>;
|
|
14
|
+
type: ResourcesTypes | ResourcesTypes[];
|
|
15
|
+
strategy: Strategy;
|
|
16
|
+
}
|
|
17
|
+
export type ResourcesTypes = 'script' | 'style' | 'image' | 'font' | 'manifest' | 'html';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResourcesTypes, WarmStrategyCacheOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/warmStrategyCache.ts
|
|
4
|
+
*/
|
|
5
|
+
export declare function warmStrategyCache(options: WarmStrategyCacheOptions): void;
|
|
6
|
+
export declare function matchResourceType(type: ResourcesTypes, path: string): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/warmStrategyCache.ts
|
|
3
|
+
*/
|
|
4
|
+
function warmStrategyCache(options) {
|
|
5
|
+
self.addEventListener('install', (event) => {
|
|
6
|
+
const done = options.urls
|
|
7
|
+
.map((path) => {
|
|
8
|
+
return typeof path === 'object' ? path.url : path;
|
|
9
|
+
})
|
|
10
|
+
.filter((path) => {
|
|
11
|
+
const types = Array.isArray(options.type) ? options.type : [options.type];
|
|
12
|
+
return types.some((type) => matchResourceType(type, path));
|
|
13
|
+
})
|
|
14
|
+
.map((path) => options.strategy.handleAll({
|
|
15
|
+
event,
|
|
16
|
+
request: new Request(path),
|
|
17
|
+
})[1]);
|
|
18
|
+
event.waitUntil(Promise.all(done));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function matchResourceType(type, path) {
|
|
22
|
+
if (path.includes('?')) {
|
|
23
|
+
// eslint-disable-next-line no-param-reassign
|
|
24
|
+
[path] = path.split('?');
|
|
25
|
+
}
|
|
26
|
+
switch (type) {
|
|
27
|
+
case 'script':
|
|
28
|
+
return path.endsWith('.js');
|
|
29
|
+
case 'style':
|
|
30
|
+
return path.endsWith('.css');
|
|
31
|
+
case 'manifest':
|
|
32
|
+
return path.endsWith('.webmanifest') || path.endsWith('.json');
|
|
33
|
+
case 'image':
|
|
34
|
+
return (path.endsWith('.png') ||
|
|
35
|
+
path.endsWith('.jpg') ||
|
|
36
|
+
path.endsWith('.jpeg') ||
|
|
37
|
+
path.endsWith('.svg') ||
|
|
38
|
+
path.endsWith('.webp') ||
|
|
39
|
+
path.endsWith('.avif'));
|
|
40
|
+
case 'font':
|
|
41
|
+
return (path.endsWith('.woff') ||
|
|
42
|
+
path.endsWith('.woff2') ||
|
|
43
|
+
path.endsWith('.ttf') ||
|
|
44
|
+
path.endsWith('.otf'));
|
|
45
|
+
case 'html':
|
|
46
|
+
return ((path.startsWith(process.env.TRAMVAI_PWA_SW_SCOPE) &&
|
|
47
|
+
!matchResourceType('manifest', path)) ||
|
|
48
|
+
path.endsWith('.html'));
|
|
49
|
+
default:
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { matchResourceType, warmStrategyCache };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* reference - https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-recipes/src/warmStrategyCache.ts
|
|
7
|
+
*/
|
|
8
|
+
function warmStrategyCache(options) {
|
|
9
|
+
self.addEventListener('install', (event) => {
|
|
10
|
+
const done = options.urls
|
|
11
|
+
.map((path) => {
|
|
12
|
+
return typeof path === 'object' ? path.url : path;
|
|
13
|
+
})
|
|
14
|
+
.filter((path) => {
|
|
15
|
+
const types = Array.isArray(options.type) ? options.type : [options.type];
|
|
16
|
+
return types.some((type) => matchResourceType(type, path));
|
|
17
|
+
})
|
|
18
|
+
.map((path) => options.strategy.handleAll({
|
|
19
|
+
event,
|
|
20
|
+
request: new Request(path),
|
|
21
|
+
})[1]);
|
|
22
|
+
event.waitUntil(Promise.all(done));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function matchResourceType(type, path) {
|
|
26
|
+
if (path.includes('?')) {
|
|
27
|
+
// eslint-disable-next-line no-param-reassign
|
|
28
|
+
[path] = path.split('?');
|
|
29
|
+
}
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 'script':
|
|
32
|
+
return path.endsWith('.js');
|
|
33
|
+
case 'style':
|
|
34
|
+
return path.endsWith('.css');
|
|
35
|
+
case 'manifest':
|
|
36
|
+
return path.endsWith('.webmanifest') || path.endsWith('.json');
|
|
37
|
+
case 'image':
|
|
38
|
+
return (path.endsWith('.png') ||
|
|
39
|
+
path.endsWith('.jpg') ||
|
|
40
|
+
path.endsWith('.jpeg') ||
|
|
41
|
+
path.endsWith('.svg') ||
|
|
42
|
+
path.endsWith('.webp') ||
|
|
43
|
+
path.endsWith('.avif'));
|
|
44
|
+
case 'font':
|
|
45
|
+
return (path.endsWith('.woff') ||
|
|
46
|
+
path.endsWith('.woff2') ||
|
|
47
|
+
path.endsWith('.ttf') ||
|
|
48
|
+
path.endsWith('.otf'));
|
|
49
|
+
case 'html':
|
|
50
|
+
return ((path.startsWith(process.env.TRAMVAI_PWA_SW_SCOPE) &&
|
|
51
|
+
!matchResourceType('manifest', path)) ||
|
|
52
|
+
path.endsWith('.html'));
|
|
53
|
+
default:
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.matchResourceType = matchResourceType;
|
|
59
|
+
exports.warmStrategyCache = warmStrategyCache;
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tramvai/pwa-recipes",
|
|
3
|
+
"version": "2.121.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "lib/index.es.js",
|
|
7
|
+
"typings": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git@github.com:Tinkoff/tramvai.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tramvai-build --forPublish --preserveModules",
|
|
19
|
+
"watch": "tsc -w"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"workbox-routing": "^6.6.1",
|
|
26
|
+
"workbox-strategies": "^6.6.1",
|
|
27
|
+
"workbox-expiration": "^6.6.1",
|
|
28
|
+
"workbox-cacheable-response": "^6.6.1",
|
|
29
|
+
"workbox-precaching": "^6.6.1"
|
|
30
|
+
}
|
|
31
|
+
}
|