Skip to content

Conversation

@SkyZeroZx
Copy link
Contributor

@SkyZeroZx SkyZeroZx commented Jul 20, 2025

This commit adds support for the updateViaCache option when configuring Angular Service Workers.

The change includes:

  • Added updateViaCache to SwRegistrationOptions interface
  • Modified service worker registration to pass the updateViaCache option
  • Added comprehensive unit tests to verify the new functionality
  • Updated existing tests to include the new option

Motivation/Use Cases

The updateViaCache option is particularly useful for:

  • Fine-grained cache control: Determining when the browser consults the HTTP cache during service worker updates
  • Performance optimization: Controlling caching behavior for service worker scripts and imported scripts
  • Development workflows: Better control over service worker update mechanisms during development and production
  • Compliance with PWA best practices: Aligning with modern service worker registration standards

Proposed Solution

  • Add updateViaCache property to the SwRegistrationOptions abstract class
  • Implement property handling in the service worker registration logic
  • Pass the option through to the native navigator.serviceWorker.register() API
  • Maintain full backward compatibility with existing configurations

Examples of New Usage

Basic configuration with provideServiceWorker

export const appConfig: ApplicationConfig = {
  providers: [
    provideServiceWorker('ngsw-worker.js', {
      enabled: !isDevMode(),
      updateViaCache: 'imports',
      registrationStrategy: 'registerWhenStable:30000',
    }),
  ],
};

…ceWorker

Enables configuration of the updateViaCache setting for service worker registration, allowing greater control over caching behavior during updates. Extends tests to cover new option and ensures correct propagation in registration logic.
@pullapprove pullapprove bot requested a review from thePunderWoman July 20, 2025 19:27
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: service-worker Issues related to the @angular/service-worker package labels Jul 20, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 20, 2025
…deServiceWorker

Enables configuration of the updateViaCache setting for service worker registration, allowing greater control over caching behavior during updates. Extends tests to cover new option and ensures correct propagation in registration logic.
@SkyZeroZx
Copy link
Contributor Author

@thePunderWoman You can run it again. I already corrected some unit tests that I had not been able to run locally. I just learned how to run them due to environmental differences.

@SkyZeroZx
Copy link
Contributor Author

SkyZeroZx commented Jul 21, 2025

@thePunderWoman You can run it again, it seems there is flaky test in firefox, locally they worked for me123123

In pipeline error show by timeout
image

Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

reviewed-for: fw-general, public-api

@pullapprove pullapprove bot requested review from atscott, devversion and mmalerba July 22, 2025 12:32
@thePunderWoman thePunderWoman added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Jul 22, 2025
@devversion devversion removed their request for review July 22, 2025 13:15
@pullapprove pullapprove bot requested a review from JeanMeche July 22, 2025 13:15
Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 22, 2025
@kirjs
Copy link
Contributor

kirjs commented Jul 22, 2025

This PR was merged into the repository by commit 4ac6171.

The changes were merged into the following branches: main

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants