workbox icon indicating copy to clipboard operation
workbox copied to clipboard

Make `revision` optional when `integrity` is set in precache manifest

Open RandomEngy opened this issue 2 years ago • 2 comments

Library Affected: workbox-build, v6.4.1

Browser & Platform: All browsers

Issue or Feature Request Description: The precache manifest that's injected has entries that look like this:

{"revision":null,"url":"/bundles/v1/myScript.f3e2692d7ee7e59d5def.js"}

If you set revision to undefined instead of null, it would be left out of the JSON entirely and make a smaller bundle.

export declare interface PrecacheEntry {
    integrity?: string;
    url: string;
    revision?: string | null;
}

Might be better as

revision?: string | undefined;

RandomEngy avatar Dec 03 '21 20:12 RandomEngy

At some point this might change, but for the time being, we want an explicit null there as a signal that the revision field has been deliberately set, rather than someone manually creating a precache manifest entry without taking verisoning into account at all.

(This is obviously not foolproof, but it's part of a best-effort to prevent developers from mistakenly, e.g., adding {url: '/index.html'} to their precache manifest and then getting very confused when they make changes to index.html, but caches are never updated.)

In Workbox v7, I anticipate we're going to start generating integrity properties (for subresource integrity) via the build tools. If we see that integrity is set, a missing revision would probably be fine.

jeffposnick avatar Dec 03 '21 21:12 jeffposnick

Makes sense, thanks for the explanation.

RandomEngy avatar Dec 03 '21 21:12 RandomEngy