New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(service-worker): Support ignoring specific URLs #30195
Comments
As mentioned in #21191 (comment) I would try intercepting. If intercepting using https://angular.io/api/common/http/HttpInterceptor or the example with Posting a map of URL's may not be sufficient either as in some cases you don't know the URL, because it's given to you as a response from another call. An example is one of my own use-cases where I'm using git for offline storage in the browser and git LFS for dealing with large files. To get the upload URL (which I want the serviceworker to bypass), I need to make a post request first, which returns the upload URL. You can see where it happens here: https://github.com/fintechneo/angular-git-filebrowser/blob/master/src/lib/gitbackend/gitbackend.service.ts#L898 In this case it's easy for me to send headers, either by intercepting or modyfing the library itself of course, but a URL map wouldn't help much. Also when introducing URL maps, you'd probably soon discover that just matching URL's isn't enough. You'd want to match URL patterns, which method is used etc. We'd end up with lot's of logic in the serviceworker for handling this, while it could probably be solved more easily in the client. In the client code you can have tailored code for intercepting and checking requests. Thinking out loud, there's a another alternative: instead of sending a map of URL's to bypass, you could send function code to the serviceworker that it should use to check the requests. I haven't thought through what side-effects that could cause, but it would at least give you full control over the logic for bypassing the serviceworker. @aSegatto @gkalpak |
I thought that sw had already some sort of glob logic, to know how to handle data api requests but if it has not, i agree it's a lot of work to do ... maybe just adding or removing urls dynamically from the map in the sw could do the trick, but of course you need to know the exact url. Sending a function to the sw is very powerful, but i think wouldn't be considered a good practice by many as you should eval code on the fly. |
Yeah, sending a function for the SW to evaluate is probably not a good idea 馃榿 To recap: The decision about whether to handle the request or not has to be made in a way that does not violate the following assumptions: One way to achieve this is by making the decision on the app side and communicating it to the SW via some form of metadata embedded into the request itself (e.g. custom query param or header - this is already supported). This will work in cases where you can control the URL/request, but there are still cases where this isn't possible (which is what this issue is about). |
So this is where one probably could consider adding "SDK features" to the serviceworker module, so that it would be possible to compile your own This would maybe involve additions to the CLI, and also is much about documentation (serviceworker cookbook). Is that an idea? |
Another idea: Add property in |
WRT #30195 (comment): WRT #30195 (comment): |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
Given the relatively low demand for this feature and the fact that there doesn't seem to be a good solution (that doesn't require a SW re-write 馃榿), I am going to close this. For anyone that absolutely needs this with the Angular ServiceWorker, there are the work-arounds referenced in the issue description (such as #21191 (comment)). The more generic feature of making it possible to extend/modify the ServiceWorker logic is being tracked in other issues; in particular #21197 (and also #24387 and #26413 for the specific case of overriding |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
馃殌 feature request
Relevant Package
This feature request is for @angular/service-worker
Description
While forcing the SW to ignore specific URL is now possible adding http header
ngsw-bypass
orngsw-bypass=true
as query param, it's not possible to specify some URLs to be ignored. This would be very useful when dealing with SDKs like Firestore, that don't allow to edit the http requests.Describe the solution you'd like
As discussed in #21191 some workarounds are possible : #21191 (Comment) or 21192 (Comment).
Second comment also contains a suggestion on how to modify SW in order to implement the requested feature. This would mean accepting messages to allow to set a list of URLs to ignore.
The text was updated successfully, but these errors were encountered: