Skip to content

feat(service-worker): Adds for type in provideServiceWorker #62831

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SkyZeroZx
Copy link
Contributor

feat(service-worker): Add type option to provideServiceWorker

Enables specifying the script type ('classic' or 'module') when registering Service Workers, improving compatibility with ES module features.

The change includes:

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

Motivation/Use Cases

The type option is particularly useful for:

  • ES Module support: Enabling ES module features like import/export in service worker scripts
  • Modern JavaScript: Supporting modern JavaScript syntax and module system in service workers
  • Compliance with PWA best practices: Aligning with modern service worker registration standards

Proposed Solution

  • Add type 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 (defaults to 'classic')

Examples of New Usage

Basic configuration with provideServiceWorker

export const appConfig: ApplicationConfig = {
  providers: [
    provideServiceWorker('ngsw-worker.js', {
      enabled: !isDevMode(),
      type: 'module', // Enable ES module features
    }),
  ],
};

@pullapprove pullapprove bot requested a review from AndrewKushnir July 26, 2025 06:03
@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 26, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 26, 2025
Enables specifying the script type ('classic' or 'module') when registering Service Workers, improving compatibility with ES module features.
@SkyZeroZx SkyZeroZx force-pushed the add-service-worker-type branch from 2ec391b to 3b82c3e Compare July 26, 2025 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: service-worker Issues related to the @angular/service-worker package detected: feature PR contains a feature commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant