You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow for service worker to be bypassed entirely for certain URL patterns #25007
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ X ] 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
[ ] Other... Please describe:
Current behavior
Currently the service worker always handles the request response, even if it eventually passes straight to the fetch API. This is fine since in theory the fetch API does exactly what the browser would have, but this is not always the case in practice and the fetch API still has bugs in it. In my case, streaming long videos is not handled well at all by the fetch API.
Expected behavior
Would be great for these situations to be able to specify a set of URLs / Patterns to entirely bypass the service worker and the fetch API.
Minimal reproduction of the problem with instructions
No steps, just no possible way to do this right now without manually rewriting ngsw-worker.js post build.
What is the motivation / use case for changing the behavior?
As stated, the fetch API isn't perfect and sometimes the best solution is just to bypass it.
Environment
Angular version: X.Y.Z
Browser:
- [ ] 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: XX
- Platform:
Others:
One problem with this is that there is no way to synchronously determine if a URL should be handled or not. We have to first retrieve the manifest (aka AppVersion) that serves the current client and then look at its list of excluded URLs.
The question is whether or not we can delay the decision of whether a request will be handled by the SW or not (here). If this needs to happen synchronously, then we're out of luck. (If someone wanted to investigate this and report back, that would be rad 😁)
Alternatively, another way out would be built-in support for enhancing ngsw-worker.js (via some sort of SW polyfills) as described in #20756 (comment).
I don't know. Maybe. That's the thing that needs investigation 😁
I.e. is it possible to use event.waitUntil(), do the check asynchronously and then decide we don't want to handle the request.
Good point, tried a few different set ups and have had no luck so far getting it to work async. Seems like even using waitUntil, the fetch event wants a synchronous response. Seems like your other suggestion would be the way to go with it if it were to be implemented unless someone more experienced than I with service workers can get it.
The workaround as it stands is less than ideal given it's build and deployment implications, and makes angular service workers problematic for any site delivering things like streaming content.
title may be misleading, the service worker doesn't need to be bypassed, it just needs to not try to route the request through the fetch api and let the browser handle it natively.
Another thread that concludes it is not possible to do that. The bottom-line is that calling fetch(event.request) from the SW should have the exact same behavior (so it is a browser implementation issue if it doesn't, not a spec issue) 🤷♂️
Yea it makes sense that the worker needs to tell the browser synchronously who is handling the request. A fuller solution would be to alter the build process so the service worker conf is built into the worker itself so that it can be initialized synchronously. There is nothing stopping the worker from requesting new copies of itself to check for updates.
However, I think this does make angular service workers non viable for media intensive applications. I understand this is a bug in fetch and not angular itself, but it's still a big problem that needs a work around.
Activity
gkalpak commentedon Jul 20, 2018
One problem with this is that there is no way to synchronously determine if a URL should be handled or not. We have to first retrieve the manifest (aka
AppVersion) that serves the current client and then look at its list of excluded URLs.The question is whether or not we can delay the decision of whether a request will be handled by the SW or not (here). If this needs to happen synchronously, then we're out of luck. (If someone wanted to investigate this and report back, that would be rad 😁)
Alternatively, another way out would be built-in support for enhancing
ngsw-worker.js(via some sort of SW polyfills) as described in #20756 (comment).bd60 commentedon Jul 20, 2018
waitUntil cant' be used to run an initilization check?
gkalpak commentedon Jul 20, 2018
I don't know. Maybe. That's the thing that needs investigation 😁
I.e. is it possible to use
event.waitUntil(), do the check asynchronously and then decide we don't want to handle the request.bd60 commentedon Jul 20, 2018
Good point, tried a few different set ups and have had no luck so far getting it to work async. Seems like even using waitUntil, the fetch event wants a synchronous response. Seems like your other suggestion would be the way to go with it if it were to be implemented unless someone more experienced than I with service workers can get it.
The workaround as it stands is less than ideal given it's build and deployment implications, and makes angular service workers problematic for any site delivering things like streaming content.
manklu commentedon Jul 20, 2018
It seems that it is currently impossible to bypass a service worker.
See w3c/ServiceWorker#1026
bd60 commentedon Jul 20, 2018
title may be misleading, the service worker doesn't need to be bypassed, it just needs to not try to route the request through the fetch api and let the browser handle it natively.
gkalpak commentedon Jul 21, 2018
Unfortunately, my understanding of the spec is that
respondWith()is a decision that needs to be made synchronously 😞gkalpak commentedon Jul 21, 2018
Another thread that concludes it is not possible to do that. The bottom-line is that calling
fetch(event.request)from the SW should have the exact same behavior (so it is a browser implementation issue if it doesn't, not a spec issue) 🤷♂️bd60 commentedon Jul 21, 2018
Yea it makes sense that the worker needs to tell the browser synchronously who is handling the request. A fuller solution would be to alter the build process so the service worker conf is built into the worker itself so that it can be initialized synchronously. There is nothing stopping the worker from requesting new copies of itself to check for updates.
However, I think this does make angular service workers non viable for media intensive applications. I understand this is a bug in fetch and not angular itself, but it's still a big problem that needs a work around.
gkalpak commentedon Sep 17, 2018
Closing as a duplicate of #21191. Let's track the issue there.
angular-automatic-lock-bot commentedon Sep 14, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.