feat(service-worker): support multiple apps on different subpaths of a domain (#27080)

Previously, it was not possible to have multiple apps (using
`@angular/service-worker`) on different subpaths of the same domain,
because each SW would overwrite the caches of the others (even though
their scope was different).

This commit fixes it by ensuring that the cache names created by the SW
are different for each scope.

Fixes #21388

PR Close #27080
This commit is contained in:
Sheik Althaf
2019-03-20 23:29:15 +02:00
committed by Matias Niemelä
parent 37a154e4e6
commit e721c08c7f
7 changed files with 34 additions and 15 deletions

View File

@ -74,6 +74,7 @@ export class MockClients implements Clients {
}
export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context {
readonly cacheNamePrefix: string;
readonly clients = new MockClients();
private eventHandlers = new Map<string, Function>();
private skippedWaiting = true;
@ -115,6 +116,8 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context
constructor(private server: MockServerState, readonly caches: MockCacheStorage) {
this.time = Date.now();
const baseHref = new URL(this.registration.scope).pathname;
this.cacheNamePrefix = 'ngsw:' + baseHref;
}
async resolveSelfMessages(): Promise<void> {