UNPKG

1.04 kBJavaScriptView Raw
1/*
2 Copyright 2019 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 { getOrCreatePrecacheController } from './getOrCreatePrecacheController.js';
9import { generateURLVariations } from './generateURLVariations.js';
10import '../_version.js';
11/**
12 * This function will take the request URL and manipulate it based on the
13 * configuration options.
14 *
15 * @param {string} url
16 * @param {Object} options
17 * @return {string} Returns the URL in the cache that matches the request,
18 * if possible.
19 *
20 * @private
21 */
22export const getCacheKeyForURL = (url, options) => {
23 const precacheController = getOrCreatePrecacheController();
24 const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
25 for (const possibleURL of generateURLVariations(url, options)) {
26 const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
27 if (possibleCacheKey) {
28 return possibleCacheKey;
29 }
30 }
31};