UNPKG

1.05 kBJavaScriptView Raw
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 '../_version.js';
9/**
10 * A plugin, designed to be used with PrecacheController, to translate URLs into
11 * the corresponding cache key, based on the current revision info.
12 *
13 * @private
14 */
15class PrecacheCacheKeyPlugin {
16 constructor({ precacheController }) {
17 this.cacheKeyWillBeUsed = async ({ request, params, }) => {
18 // Params is type any, can't change right now.
19 /* eslint-disable */
20 const cacheKey = (params === null || params === void 0 ? void 0 : params.cacheKey) ||
21 this._precacheController.getCacheKeyForURL(request.url);
22 /* eslint-enable */
23 return cacheKey
24 ? new Request(cacheKey, { headers: request.headers })
25 : request;
26 };
27 this._precacheController = precacheController;
28 }
29}
30export { PrecacheCacheKeyPlugin };