feat(service-worker): include CacheQueryOptions
options in ngsw-config (#34663)
Previously it was not possible to provide `CacheQueryOptions` ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Cache)) for querying the Cache. This commit introduces a new parameter called `cacheQueryOptions` for `DataGroup` and `AssetGroup`. Currently only `ignoreSearch` is supported as `ignoreVary` and `ignoreMethod` would require using the complete Request object for matching which is not possible with the current implementation. Closes #28443 PR Close #34663
This commit is contained in:

committed by
Alex Rickabaugh

parent
49be32c931
commit
dc9f4b994e
@ -92,6 +92,7 @@ describe('Generator', () => {
|
||||
'\\/some\\/url\\?with\\+escaped\\+chars',
|
||||
'\\/test\\/relative\\/[^/]*\\.txt',
|
||||
],
|
||||
cacheQueryOptions: undefined,
|
||||
}],
|
||||
dataGroups: [{
|
||||
name: 'other',
|
||||
@ -105,6 +106,7 @@ describe('Generator', () => {
|
||||
maxAge: 259200000,
|
||||
timeoutMs: 60000,
|
||||
version: 1,
|
||||
cacheQueryOptions: undefined,
|
||||
}],
|
||||
navigationUrls: [
|
||||
{positive: true, regex: '^\\/included\\/absolute\\/.*$'},
|
||||
@ -181,4 +183,76 @@ describe('Generator', () => {
|
||||
'which is no longer supported. Use \'files\' instead.'));
|
||||
}
|
||||
});
|
||||
|
||||
it('generates a correct config with cacheQueryOptions', async () => {
|
||||
const fs = new MockFilesystem({
|
||||
'/index.html': 'This is a test',
|
||||
'/main.js': 'This is a JS file',
|
||||
});
|
||||
const gen = new Generator(fs, '/');
|
||||
const config = await gen.process({
|
||||
index: '/index.html',
|
||||
assetGroups: [{
|
||||
name: 'test',
|
||||
resources: {
|
||||
files: [
|
||||
'/**/*.html',
|
||||
'/**/*.?s',
|
||||
]
|
||||
},
|
||||
cacheQueryOptions: {ignoreSearch: true},
|
||||
}],
|
||||
dataGroups: [{
|
||||
name: 'other',
|
||||
urls: ['/api/**'],
|
||||
cacheConfig: {
|
||||
maxAge: '3d',
|
||||
maxSize: 100,
|
||||
strategy: 'performance',
|
||||
timeout: '1m',
|
||||
},
|
||||
cacheQueryOptions: {ignoreSearch: false},
|
||||
}]
|
||||
});
|
||||
|
||||
expect(config).toEqual({
|
||||
configVersion: 1,
|
||||
appData: undefined,
|
||||
timestamp: 1234567890123,
|
||||
index: '/index.html',
|
||||
assetGroups: [{
|
||||
name: 'test',
|
||||
installMode: 'prefetch',
|
||||
updateMode: 'prefetch',
|
||||
urls: [
|
||||
'/index.html',
|
||||
'/main.js',
|
||||
],
|
||||
patterns: [],
|
||||
cacheQueryOptions: {ignoreSearch: true}
|
||||
}],
|
||||
dataGroups: [{
|
||||
name: 'other',
|
||||
patterns: [
|
||||
'\\/api\\/.*',
|
||||
],
|
||||
strategy: 'performance',
|
||||
maxSize: 100,
|
||||
maxAge: 259200000,
|
||||
timeoutMs: 60000,
|
||||
version: 1,
|
||||
cacheQueryOptions: {ignoreSearch: false}
|
||||
}],
|
||||
navigationUrls: [
|
||||
{positive: true, regex: '^\\/.*$'},
|
||||
{positive: false, regex: '^\\/(?:.+\\/)?[^/]*\\.[^/]*$'},
|
||||
{positive: false, regex: '^\\/(?:.+\\/)?[^/]*__[^/]*$'},
|
||||
{positive: false, regex: '^\\/(?:.+\\/)?[^/]*__[^/]*\\/.*$'},
|
||||
],
|
||||
hashTable: {
|
||||
'/index.html': 'a54d88e06612d820bc3be72877c74f257b561b19',
|
||||
'/main.js': '41347a66676cdc0516934c76d9d13010df420f2c',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user