Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/service-worker/worker/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ export abstract class AssetGroup {
cacheDirectives.forEach(v => v[0] = v[0].toLowerCase());

// 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxAgeDirective[1] ?


if (cacheAge.length === 0) {
if (!cacheAge) {
// No usable TTL defined. Must assume that the response is stale.
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/service-worker/worker/test/happy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const dist =
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
.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();

const distUpdate =
Expand Down Expand Up @@ -621,6 +622,13 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
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() => {
expect(await makeRequest(scope, '/unhashed/a.txt', 'default', {
credentials: 'include'
Expand Down