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
Feature: Ability to force cors mode for some asset/data groups in service worker #47729
Which @angular/* package(s) are relevant/related to the feature request?
service-worker
Description
When using resources from a cross origin, by default fetch() is using cors mode but it's not the case when using <img> and other media element, or url() in CSS, browser defaults to no-cors and is able to use opaque response.
For HTML element, it's possible to force cors mode with the crossorigin attribute, but it's not possible in CSS.
Even when server is configured correctly for CORS, it will usually not responds any CORS headers when the request is made in no-cors mode.
In Service Worker, when handling a request to a different origin in no-cors mode, the response will be considered opaque and can't cached or at least not "safely" in a performance strategy because it will also cache error response (as stated in documentation).
Having the possibility to force cors mode for specific url patterns that we know are correctly configured and will handle CORS could ease the use of performance strategy and offline use-case when cross origin resources are involved.
It might be similar to #38907 (and PR #24510) but with ability to specify request option only on a group.
Proposed solution
Add an option for AssetGroup and DataGroup to force the group to be requested using cors mode when fetched.
It might be interesting in some case to also be able to pass a credentials option.
With an option specific on each group, it's really an opt-in for chosen url patterns, and it will not affects anything else.
Alternatives considered
I don't really see any. I've tried the alternative proposed by documentation, which is to use freshness strategy, but as SW will not differentiate valide opaque response and error, it will cache error and introduce unexpected behavior when offline. Also opaque response have negative impact on the estimation usage of the Storage API.
Activity
JeanMeche commentedon Aug 29, 2025
With #63364 we've announced that the service-worker package in now in maintenance mode and will not receive feature PRs and feature requests.
The message is also visible here: https://angular.dev/ecosystem/service-workers
angular-automatic-lock-bot commentedon Sep 29, 2025
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.