Skip to content

Commit 157ccda

Browse files
committed
docs: add service workers reference to angular developer skill
1 parent ee25bb1 commit 157ccda

2 files changed

Lines changed: 93 additions & 5 deletions

File tree

‎skills/dev-skills/angular-developer/SKILL.md‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: angular-developer
3-
description: Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.
3+
description: Generates Angular code and provides architectural guidance. Trigger when creating projects, components, services, or HTTP communication, or for best practices on reactivity (signals, linkedSignal, resource, httpResource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.
44
license: MIT
55
metadata:
66
author: Copyright 2026 Google LLC
@@ -17,7 +17,7 @@ metadata:
1717

1818
## Creating New Projects
1919

20-
If no guidelines are provided by the user, here are same default rules to follow when creating a new Angular project:
20+
If no guidelines are provided by the user, here are some default rules to follow when creating a new Angular project:
2121

2222
1. Use the latest stable version of Angular unless the user specifies otherwise.
2323
2. Use Signals Forms for form management in new projects (available in Angular v21 and newer) [Find out more](references/signal-forms.md).
@@ -61,12 +61,18 @@ When managing state and data reactivity, use Angular Signals and consult the fol
6161
- **Async Reactivity (`resource`)**: Fetching asynchronous data directly into signal state. Read [resource.md](references/resource.md)
6262
- **Side Effects (`effect`)**: Logging, third-party DOM manipulation (`afterRenderEffect`), and when NOT to use effects. Read [effects.md](references/effects.md)
6363

64+
## HTTP Communication
65+
66+
When communicating with backend services, use Angular HTTP APIs and consult the following reference:
67+
68+
- **HTTP Client and Resources**: `provideHttpClient`, `HttpClient`, interceptors, and `httpResource`. Read [http-client.md](references/http-client.md)
69+
6470
## Forms
6571

6672
In most cases for new apps, **prefer signal forms**. When making a forms decision, analyze the project and consider the following guidelines:
6773

68-
- if the application is using v21 or newer and this is a new form, **prefer signal forms**.
69-
-For older applications or when working with existing forms, use the appropriate form type that matches the applications current form strategy.
74+
- If the application is using v21 or newer and this is a new form, **prefer signal forms**.
75+
- For older applications or when working with existing forms, use the appropriate form type that matches the applications current form strategy.
7076

7177
- **Signal Forms**: Use signals for form state management. Read [signal-forms.md](references/signal-forms.md)
7278
- **Template-driven forms**: Use for simple forms. Read [template-driven-forms.md](references/template-driven-forms.md)
@@ -82,6 +88,12 @@ When implementing dependency injection in Angular, follow these guidelines:
8288
- **Injection Context**: Where `inject()` is allowed, `runInInjectionContext`, and `assertInInjectionContext`. Read [injection-context.md](references/injection-context.md)
8389
- **Hierarchical Injectors**: The `EnvironmentInjector` vs `ElementInjector`, resolution rules, modifiers (`optional`, `skipSelf`), and `providers` vs `viewProviders`. Read [hierarchical-injectors.md](references/hierarchical-injectors.md)
8490

91+
## Pipes
92+
93+
When formatting values in templates, creating custom pipes, or reusing pipe-like logic in TypeScript, consult the following reference. Prefer pipes in templates; outside templates, avoid injecting pipe classes just to call `transform()`.
94+
95+
- **Pipes**: Built-in pipe imports, custom pipe naming and implementation, pure vs impure pipes, and TypeScript reuse patterns using standalone formatting functions or extracted plain functions. Read [pipes.md](references/pipes.md)
96+
8597
## Angular Aria
8698

8799
When building accessible custom components for any of the following patterns: Accordion, Listbox, Combobox, Menu, Tabs, Toolbar, Tree, Grid, consult the following reference:
@@ -119,13 +131,14 @@ When writing or updating tests, consult the following references based on the ta
119131
- **Fundamentals**: Best practices for unit testing (Vitest), async patterns, and `TestBed`. Read [testing-fundamentals.md](references/testing-fundamentals.md)
120132
- **Component Harnesses**: Standard patterns for robust component interaction. Read [component-harnesses.md](references/component-harnesses.md)
121133
- **Router Testing**: Using `RouterTestingHarness` for reliable navigation tests. Read [router-testing.md](references/router-testing.md)
122-
- **End-to-End (E2E) Testing**: Best practices for E2E tests with Cypress. Read [e2e-testing.md](references/e2e-testing.md)
134+
- **End-to-End (E2E) Testing**: Setting up and running E2E tests. Read [e2e-testing.md](references/e2e-testing.md)
123135

124136
## Tooling
125137

126138
When working with Angular tooling, consult the following references:
127139

128140
- **Angular CLI**: Creating applications, generating code (components, routes, services), serving, and building. Read [cli.md](references/cli.md)
141+
- **Service Workers / PWA**: Enabling offline support, precaching, runtime caching, and update prompts. Read [service-workers.md](references/service-workers.md)
129142
- **Code Modernization**: Automatically refactoring to modern standards using migrations. Read [migrations.md](references/migrations.md)
130143
- **Angular MCP Server**: Available tools, configuration, and experimental features. Read [mcp.md](references/mcp.md)
131144
- **Environment Configuration**: Strategies for build-time and runtime configuration. Read [environment-configuration.md](references/environment-configuration.md)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Angular Service Workers
2+
3+
Angular service workers enable Progressive Web App features such as offline support, precaching, runtime caching, and update handling.
4+
5+
## When to Use Service Workers
6+
7+
Use service workers when you want to:
8+
9+
- make an application available offline after first load,
10+
- precache the app shell and core assets,
11+
- cache API responses or static assets for faster repeat visits,
12+
- provide update prompts so users can refresh to the latest build.
13+
14+
## Setup
15+
16+
Prefer Angular's built-in service worker support over a custom implementation.
17+
18+
1. Add the package with `ng add @angular/pwa` when needed.
19+
2. Register the service worker with `provideServiceWorker` in the app configuration.
20+
3. Review or create an `ngsw-config.json` file for asset and data groups.
21+
4. Build and deploy the app in production mode to test the worker behavior.
22+
23+
## Recommended Patterns
24+
25+
- Use `assetGroups` for static files such as JS, CSS, images, and fonts.
26+
- Use `dataGroups` for API requests that should be cached with a strategy like `networkFirst`.
27+
- Use `cacheFirst` or `staleWhileRevalidate` for assets that change infrequently.
28+
- Use `SwUpdate` to detect new versions and invite the user to refresh.
29+
30+
## Update Handling with SwUpdate
31+
32+
Use `SwUpdate` to react to available versions and activate updates with a modern Angular pattern:
33+
34+
```ts
35+
import {Component, DestroyRef, inject, signal} from '@angular/core';
36+
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
37+
import {SwUpdate} from '@angular/service-worker';
38+
39+
@Component({
40+
selector: 'app-root',
41+
template: `
42+
@if (updatesAvailable()) {
43+
<button type="button" (click)="reload()">Update available</button>
44+
}
45+
`,
46+
})
47+
export class AppComponent {
48+
private readonly updates = inject(SwUpdate);
49+
readonly updatesAvailable = signal(false);
50+
51+
constructor() {
52+
const destroyRef = inject(DestroyRef);
53+
54+
this.updates.versionUpdates.pipe(takeUntilDestroyed(destroyRef)).subscribe(() => {
55+
this.updatesAvailable.set(true);
56+
});
57+
}
58+
59+
reload(): void {
60+
this.updates.activateUpdate().then(() => window.location.reload());
61+
}
62+
}
63+
```
64+
65+
## Avoid Common Pitfalls
66+
67+
- Avoid caching sensitive or user-specific data unless that behavior is explicitly required.
68+
- Do not rely on service workers in development; test with a production build.
69+
- Keep caching policies narrow and versioned to avoid stale content.
70+
71+
## Reference
72+
73+
For full details, see the official Angular documentation:
74+
75+
- https://angular.dev/ecosystem/service-workers

0 commit comments

Comments
 (0)