Skip to content

The function cacheVersioned() doesn't update to newer assets #2

@zhirzh

Description

@zhirzh

in the section cache smarter, the function cacheVersioned() is intended to cache assets that may change over time.

async function cacheVersioned(version, assets) {
  const exists = await caches.has(`version-${version}`);
  if (!exists) {
    const requests = assets.map(asset => new Request(asset));
    const preCachedResponses =
      await Promise.all(requests.map(req => caches.match(req)));
    const cache = await caches.open(`version-${version}`);
    return Promise.all(requests.map((request, idx) => {
      return preCachedResponses[idx]
        ? cache.put(request, preCachedResponses[idx].clone())
        : cache.add(request);
    }));
  }
}

But, AFAIK, the code will fail to do so. The function only checks if a Response already exists, not the content of the response (since that is impossible).

The technique will only work if the URL itself changes (hashes?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions