From f592a120057c3787ad6b7385b6f8e10928627e9e Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 8 Jul 2021 16:22:49 +0300 Subject: [PATCH] fix(service-worker): avoid storing redundant metadata for hashed assets (#42606) The ServiceWorker needs to keep track of some metadata for unhashed asset resources to know if/when they might need to be revalidated. This applies to resources that do not exist on the filesystem at build-time (and thus cannot be hashed), such as fonts or images loaded from external sources. For hashed resources, this metadata is irrelevant, because the hash is enough to verify that the content hasn't changed and no revalidation is necessary. Previously, the ServiceWorker would store such metadata for hashed resources as well, even though it would never be used (thus taking up space unnecessarily). This commit fixes it by not storing metadata for hashed resources, i.e. those that are included in an asset-group's `hashes` array. PR Close #42606 --- packages/service-worker/worker/src/assets.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/service-worker/worker/src/assets.ts b/packages/service-worker/worker/src/assets.ts index f3beb8a421..b6650ff0e6 100644 --- a/packages/service-worker/worker/src/assets.ts +++ b/packages/service-worker/worker/src/assets.ts @@ -454,7 +454,6 @@ export abstract class AssetGroup { protected async maybeUpdate(updateFrom: UpdateSource, req: Request, cache: Cache): Promise { const url = this.adapter.normalizeUrl(req.url); - const meta = await this.metadata; // Check if this resource is hashed and already exists in the cache of a prior version. if (this.hashes.has(url)) { const hash = this.hashes.get(url)!; @@ -467,7 +466,6 @@ export abstract class AssetGroup { if (res !== null) { // Copy to this cache. await cache.put(req, res); - await meta.write(req.url, {ts: this.adapter.time, used: false} as UrlMetadata); // No need to do anything further with this resource, it's now cached properly. return true;