fix(service-worker): `Cache-Control: no-cache` on assets breaks service worker (#25408)
At the moment `cacheAge` can we undefined when having `Cache-Control` set to `no-cache` due the mapping method in `needToRevalidate` Closes #25442 PR Close #25408
This commit is contained in:
parent
be2cf4dfd6
commit
01ec5fd6b0
|
@ -193,9 +193,10 @@ export abstract class AssetGroup {
|
||||||
cacheDirectives.forEach(v => v[0] = v[0].toLowerCase());
|
cacheDirectives.forEach(v => v[0] = v[0].toLowerCase());
|
||||||
|
|
||||||
// Find the max-age directive, if one exists.
|
// Find the max-age directive, if one exists.
|
||||||
const cacheAge = cacheDirectives.filter(v => v[0] === 'max-age').map(v => v[1])[0];
|
const maxAgeDirective = cacheDirectives.find(v => v[0] === 'max-age');
|
||||||
|
const cacheAge = maxAgeDirective ? maxAgeDirective[1] : undefined;
|
||||||
|
|
||||||
if (cacheAge.length === 0) {
|
if (!cacheAge) {
|
||||||
// No usable TTL defined. Must assume that the response is stale.
|
// No usable TTL defined. Must assume that the response is stale.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ const dist =
|
||||||
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
||||||
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
||||||
.addUnhashedFile('/unhashed/a.txt', 'this is unhashed', {'Cache-Control': 'max-age=10'})
|
.addUnhashedFile('/unhashed/a.txt', 'this is unhashed', {'Cache-Control': 'max-age=10'})
|
||||||
|
.addUnhashedFile('/unhashed/b.txt', 'this is unhashed b', {'Cache-Control': 'no-cache'})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const distUpdate =
|
const distUpdate =
|
||||||
|
@ -621,6 +622,13 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
|
||||||
server.assertNoOtherRequests();
|
server.assertNoOtherRequests();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async_it(`doesn't error when 'Cache-Control' is 'no-cache'`, async() => {
|
||||||
|
expect(await makeRequest(scope, '/unhashed/b.txt')).toEqual('this is unhashed b');
|
||||||
|
server.assertSawRequestFor('/unhashed/b.txt');
|
||||||
|
expect(await makeRequest(scope, '/unhashed/b.txt')).toEqual('this is unhashed b');
|
||||||
|
server.assertNoOtherRequests();
|
||||||
|
});
|
||||||
|
|
||||||
async_it('avoid opaque responses', async() => {
|
async_it('avoid opaque responses', async() => {
|
||||||
expect(await makeRequest(scope, '/unhashed/a.txt', 'default', {
|
expect(await makeRequest(scope, '/unhashed/a.txt', 'default', {
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
|
|
Loading…
Reference in New Issue