Skip to content

Feature: Ability to force cors mode for some asset/data groups in service worker #47729

Closed as not planned

Description

@jviolas

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

  1. added this to the needsTriage milestone on Oct 11, 2022
  2. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Nov 16, 2022
  3. modified the milestones: needsTriage, Backlog on Nov 16, 2022
  4. JeanMeche commented on Aug 29, 2025

    @JeanMeche
    Member

    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

  5. angular-automatic-lock-bot commented on Sep 29, 2025

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

  6. locked and limited conversation to collaborators on Sep 29, 2025
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

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions