source: frontend/node_modules/workbox-precaching/PrecacheRoute.js

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