Closed
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The installation of a 2nd App/ServiceWorker (with different baseHref) purges the Cache Storage entries for a previously installed App/ServiceWorker, if they are on the same domain. This breaks the 1st installed App. It is not reachable anymore - you will always be redirected to the latest installed App.
Expected behavior
The installation of multiple Apps/ServiceWorkers (with different baseHref) on one domain should be possible.
Minimal reproduction of the problem with instructions
I created the following repo to reproduce the issue: https://github.com/skydever/repro-multiple-ng-apps-one-domain-serviceworker. Follow the steps of the README there.
What is the motivation / use case for changing the behavior?
I have to deploy multiple Angular Apps on one domain.
Environment
Angular version: 5.1.3
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: v8.9.1
- Platform: Windows
Others:
- http-server version 0.10.0
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
skydever commentedon Jan 12, 2018
@alxhub Could this be a valid solution at db-cache.ts?
... but I have to provide different scopes, and the scope will always be
./
by default (and wanted so to intercept all requests down the url path where the service worker script is located) ... maybe get the baseHref somehow? but how can I obtain it safely not doing something likedocument.getElementsByTagName('base')[0].href
?skydever commentedon Jan 13, 2018
found this at browser_adapter.ts:
it is related to the platform that is used and I don't know how to wire this up ...
skydever commentedon Jan 13, 2018
just get it in a safe way using document if available, sw are only available in the platform browser ...
skydever commentedon Jan 14, 2018
the
CacheDatabase
is service worker code, so no dom access there ... I can manipulate thengsw-worker.js
after the build process to include the app/baseHref info inCacheDatabase
, by replacing the 3ngsw:db:
entries withngsw:db:[app-base-href]:
...skydever commentedon Jan 17, 2018
I created an issue at the Angular CLI repo too. both are involved somehow, the baseHref option of the CLI needs to be passed to the service worker. I don't think that the service worker is able to do that without information from the CLI?
skydever commentedon Jan 24, 2018
replacing the
ngsw:db:
key seems not to work (even replacing the 6 occurences ofngsw:
with a unique key does not work, but the distinction is better if you look at theCache Storage
at the dev tools - there are some entries without thengsw:db
prefix if you just replace the 3 occurences ofngsw:db
) - the content of thecontrol
entry in theCacheDatabase
still gets overwritten from another app ...skydever commentedon Jan 26, 2018
did some more research, maybe this is helpful somehow. after renaming
ngsw:
(6 entries inngsw-worker.js
) tongsw:swAppOne
andngsw:swAppTwo
it seems to work, but the Cache Storage seems like to be in an invalid state ... I created a branch in my repo for that, justnpm install
in sw-app-one and runnpm run start-sw
and open the pages at sw-app-one and sw-app-two, then have a look into the Cache Storage in the dev tools - the entries ngsw:sw-app-two:db:control and ngsw:sw-app-one:db:control have the same values for assignments, latest and manifests - an image of it here.Afterwards I also renamed the entries
assigments
toassigmentsSwAppOne
and so on (the other way round in the commit, was to create a reproduction of the weird state). The result looks clean now, with all the renaming. but still weird somehow, I also refreshed the cache in the dev tools ...46 remaining items