source: frontend/node_modules/workbox-precaching/src/PrecacheRoute.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 Copyright 2020 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
9import {logger} from 'workbox-core/_private/logger.js';
10import {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.js';
11import {
12 RouteMatchCallback,
13 RouteMatchCallbackOptions,
14} from 'workbox-core/types.js';
15import {Route} from 'workbox-routing/Route.js';
16
17import {PrecacheRouteOptions} from './_types.js';
18import {PrecacheController} from './PrecacheController.js';
19import {generateURLVariations} from './utils/generateURLVariations.js';
20
21import './_version.js';
22
23/**
24 * A subclass of {@link workbox-routing.Route} that takes a
25 * {@link workbox-precaching.PrecacheController}
26 * instance and uses it to match incoming requests and handle fetching
27 * responses from the precache.
28 *
29 * @memberof workbox-precaching
30 * @extends workbox-routing.Route
31 */
32class PrecacheRoute extends Route {
33 /**
34 * @param {PrecacheController} precacheController A `PrecacheController`
35 * instance used to both match requests and respond to fetch events.
36 * @param {Object} [options] Options to control how requests are matched
37 * against the list of precached URLs.
38 * @param {string} [options.directoryIndex=index.html] The `directoryIndex` will
39 * check cache entries for a URLs ending with '/' to see if there is a hit when
40 * appending the `directoryIndex` value.
41 * @param {Array<RegExp>} [options.ignoreURLParametersMatching=[/^utm_/, /^fbclid$/]] An
42 * array of regex's to remove search params when looking for a cache match.
43 * @param {boolean} [options.cleanURLs=true] The `cleanURLs` option will
44 * check the cache for the URL with a `.html` added to the end of the end.
45 * @param {workbox-precaching~urlManipulation} [options.urlManipulation]
46 * This is a function that should take a URL and return an array of
47 * alternative URLs that should be checked for precache matches.
48 */
49 constructor(
50 precacheController: PrecacheController,
51 options?: PrecacheRouteOptions,
52 ) {
53 const match: RouteMatchCallback = ({
54 request,
55 }: RouteMatchCallbackOptions) => {
56 const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
57 for (const possibleURL of generateURLVariations(request.url, options)) {
58 const cacheKey = urlsToCacheKeys.get(possibleURL);
59 if (cacheKey) {
60 const integrity =
61 precacheController.getIntegrityForCacheKey(cacheKey);
62 return {cacheKey, integrity};
63 }
64 }
65 if (process.env.NODE_ENV !== 'production') {
66 logger.debug(
67 `Precaching did not find a match for ` + getFriendlyURL(request.url),
68 );
69 }
70 return;
71 };
72
73 super(match, precacheController.strategy);
74 }
75}
76
77export {PrecacheRoute};
Note: See TracBrowser for help on using the repository browser.