Skip to content

Allow for service worker to be bypassed entirely for certain URL patterns #25007

Closed

Description

@bd60

I'm submitting a...


[ ] 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:

Activity

  1. gkalpak commented on Jul 20, 2018

    @gkalpak
    Member

    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).

  2. added
    feature
    area: service-worker
    on Jul 20, 2018
  3. added this to the Backlog milestone on Jul 20, 2018
  4. bd60 commented on Jul 20, 2018

    @bd60
    Author

    waitUntil cant' be used to run an initilization check?

  5. gkalpak commented on Jul 20, 2018

    @gkalpak
    Member

    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.

  6. bd60 commented on Jul 20, 2018

    @bd60
    Author

    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.

  7. manklu commented on Jul 20, 2018

    @manklu

    It seems that it is currently impossible to bypass a service worker.

    See w3c/ServiceWorker#1026

  8. bd60 commented on Jul 20, 2018

    @bd60
    Author

    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.

  9. gkalpak commented on Jul 21, 2018

    @gkalpak
    Member

    Unfortunately, my understanding of the spec is that respondWith() is a decision that needs to be made synchronously 😞

  10. gkalpak commented on Jul 21, 2018

    @gkalpak
    Member

    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) 🤷‍♂️

  11. bd60 commented on Jul 21, 2018

    @bd60
    Author

    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.

  12. gkalpak commented on Sep 17, 2018

    @gkalpak
    Member

    Closing as a duplicate of #21191. Let's track the issue there.

  13. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    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.

  14. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerfeature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions