PrecacheCacheKeyPlugin.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. /*
  2. Copyright 2020 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. /**
  9. * A plugin, designed to be used with PrecacheController, to translate URLs into
  10. * the corresponding cache key, based on the current revision info.
  11. *
  12. * @private
  13. */
  14. class PrecacheCacheKeyPlugin {
  15. constructor({ precacheController }) {
  16. this.cacheKeyWillBeUsed = async ({ request, params, }) => {
  17. // Params is type any, can't change right now.
  18. /* eslint-disable */
  19. const cacheKey = (params === null || params === void 0 ? void 0 : params.cacheKey) ||
  20. this._precacheController.getCacheKeyForURL(request.url);
  21. /* eslint-enable */
  22. return cacheKey
  23. ? new Request(cacheKey, { headers: request.headers })
  24. : request;
  25. };
  26. this._precacheController = precacheController;
  27. }
  28. }
  29. export { PrecacheCacheKeyPlugin };