1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
- import '../_version.js';
- const REVISION_SEARCH_PARAM = '__WB_REVISION__';
- export function createCacheKey(entry) {
- if (!entry) {
- throw new WorkboxError('add-to-cache-list-unexpected-type', { entry });
- }
-
-
- if (typeof entry === 'string') {
- const urlObject = new URL(entry, location.href);
- return {
- cacheKey: urlObject.href,
- url: urlObject.href,
- };
- }
- const { revision, url } = entry;
- if (!url) {
- throw new WorkboxError('add-to-cache-list-unexpected-type', { entry });
- }
-
-
- if (!revision) {
- const urlObject = new URL(url, location.href);
- return {
- cacheKey: urlObject.href,
- url: urlObject.href,
- };
- }
-
-
- const cacheKeyURL = new URL(url, location.href);
- const originalURL = new URL(url, location.href);
- cacheKeyURL.searchParams.set(REVISION_SEARCH_PARAM, revision);
- return {
- cacheKey: cacheKeyURL.href,
- url: originalURL.href,
- };
- }
|