Skip to content

Commit 6239dfb

Browse files
committed
fixup! feat(service-worker): add support for ignoring specific URLs
1 parent 9ae2575 commit 6239dfb

6 files changed

Lines changed: 154 additions & 147 deletions

File tree

‎aio/content/guide/service-worker-config.md‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{@a glob}
2-
31
# Service worker configuration
42

53
#### Prerequisites
@@ -9,9 +7,9 @@ A basic understanding of the following:
97

108
<hr />
119

12-
The `src/ngsw-config.json` configuration file specifies which files and data URLs the Angular
13-
service worker should cache and how it should update the cached files and data. The
14-
CLI processes the configuration file during `ng build --prod`. Manually, you can process
10+
The `src/ngsw-config.json` configuration file specifies which files and data URLs the Angular
11+
service worker should cache and how it should update the cached files and data. The
12+
CLI processes the configuration file during `ng build --prod`. Manually, you can process
1513
it with the `ngsw-config` tool:
1614

1715
```sh
@@ -32,7 +30,7 @@ Example patterns:
3230
* `/*.html` specifies only HTML files in the root.
3331
* `!/**/*.map` exclude all sourcemaps.
3432

35-
Each section of the configuration file is described below.
33+
Each section of the configuration file is described below.
3634

3735
## `appData`
3836

@@ -43,6 +41,17 @@ The `SwUpdate` service includes that data in the update notifications. Many apps
4341

4442
Specifies the file that serves as the index page to satisfy navigation requests. Usually this is `/index.html`.
4543

44+
## `ignoredUrlPatterns`
45+
46+
This section enables you to specify URLs that will not be handled by the service worker. The service
47+
worker will forward matching requests to the server and neither try to retrieve responses from the
48+
cache nor serve the index page (even for navigation requests). This is useful for routes that are
49+
not part of the Angular app, but should always be handled by the server.
50+
51+
This field contains an array of URLs and glob-like URL patterns that will be matched at runtime.
52+
53+
**Note**: Currently, negative patterns (i.e. patterns beginning with `!`) are _not_ supported.
54+
4655
## `assetGroups`
4756

4857
*Assets* are resources that are part of the app version that update along with the app. They can include resources loaded from the page's origin as well as third-party resources loaded from CDNs and other external URLs. As not all such external URLs may be known at build time, URL patterns can be matched.
@@ -92,7 +101,7 @@ The `installMode` determines how these resources are initially cached. The `inst
92101

93102
For resources already in the cache, the `updateMode` determines the caching behavior when a new version of the app is discovered. Any resources in the group that have changed since the previous version are updated in accordance with `updateMode`.
94103

95-
* `prefetch` tells the service worker to download and cache the changed resources immediately.
104+
* `prefetch` tells the service worker to download and cache the changed resources immediately.
96105

97106
* `lazy` tells the service worker to not cache those resources. Instead, it treats them as unrequested and waits until they're requested again before updating them. An `updateMode` of `lazy` is only valid if the `installMode` is also `lazy`.
98107

@@ -135,7 +144,7 @@ A list of URL patterns. URLs that match these patterns will be cached according
135144
### `version`
136145
Occasionally APIs change formats in a way that is not backward-compatible. A new version of the app may not be compatible with the old API format and thus may not be compatible with existing cached resources from that API.
137146

138-
`version` provides a mechanism to indicate that the resources being cached have been updated in a backwards-incompatible way, and that the old cache entries&mdash;those from previous versions&mdash;should be discarded.
147+
`version` provides a mechanism to indicate that the resources being cached have been updated in a backwards-incompatible way, and that the old cache entries&mdash;those from previous versions&mdash;should be discarded.
139148

140149
`version` is an integer field and defaults to `0`.
141150

@@ -166,4 +175,3 @@ The Angular service worker can use either of two caching strategies for data res
166175
* `performance`, the default, optimizes for responses that are as fast as possible. If a resource exists in the cache, the cached version is used. This allows for some staleness, depending on the `maxAge`, in exchange for better performance. This is suitable for resources that don't change often; for example, user avatar images.
167176

168177
* `freshness` optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to `timeout`, does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances.
169-

0 commit comments

Comments
 (0)