Skip to content

Commit

Permalink
docs(aio): editorial pass complete
Browse files Browse the repository at this point in the history
  • Loading branch information
kapunahelewong committed Dec 5, 2017
1 parent dc39778 commit c79275b
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 63 deletions.
12 changes: 6 additions & 6 deletions aio/content/guide/service-worker-comm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Importing `ServiceWorkerModule` into your `AppModule` doesn't just register the

## `SwUpdate` service

The `SwUpdate` service gives you access to events that indicate when the service worker has discovered an available update for your app, or when it has activated such an update, meaning it is now serving content from that update to your app.
The `SwUpdate` service gives you access to events that indicate when the service worker has discovered an available update for your app or when it has activated such an update—meaning it is now serving content from that update to your app.

The `SwUpdate` service supports four separate operations:
* Getting notified of *available* updates. These are new versions of the app which will be loaded if the page is refreshed.
* Getting notified of *available* updates. These are new versions of the app to be loaded if the page is refreshed.
* Getting notified of update *activation*. This is when the service worker starts serving a new version of the app immediately.
* Asking the service worker to check the server for new updates.
* Asking the service worker to activate the latest version of the app for the current tab.

### Available & activated updates
### Available and activated updates

The two update events are `Observable` properties of `SwUpdate`:
The two update events, `available` and `activated`, are `Observable` properties of `SwUpdate`:

<code-example path="service-worker-getstart/src/app/log-update.service.ts" linenums="false" title="log-update.service.ts" region="sw-update"> </code-example>

Expand All @@ -30,11 +30,11 @@ Do this with the `checkForUpdate()` method:
<code-example path="service-worker-getstart/src/app/check-for-update.service.ts" linenums="false" title="check-for-update.service.ts" region="sw-check-update"> </code-example>


This method returns a `Promise` which indicates that the update check has completed successfully, though it does not indicate whether an update was discovered as a result of the check. Even if one is found, the service worker must still successfully download the changed files, which can fail. If successful, the `SwUpdate.available` event will indicate availability of a new version of the app.
This method returns a `Promise` which indicates that the update check has completed successfully, though it does not indicate whether an update was discovered as a result of the check. Even if one is found, the service worker must still successfully download the changed files, which can fail. If successful, the `available` event will indicate availability of a new version of the app.

### Forcing update activation

If the current tab needs to be updated to the latest app version immediately, it can ask to do so with the `SwUpdate.activateUpdate()` method:
If the current tab needs to be updated to the latest app version immediately, it can ask to do so with the `activateUpdate()` method:

<code-example path="service-worker-getstart/src/app/prompt-update.service.ts" linenums="false" title="prompt-update.service.ts" region="sw-activate"> </code-example>

Expand Down
22 changes: 11 additions & 11 deletions aio/content/guide/service-worker-configref.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Reference: Configuration file

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

```sh
$ ngsw-config dist src/ngswn-config.json /base/href
ngsw-config dist src/ngswn-config.json /base/href
```

The configuration file uses the JSON format. All file paths must begin with `/`, which is the deployment directory&mdash;usually `dist` in CLI projects).
The configuration file uses the JSON format. All file paths must begin with `/`, which is the deployment directory&mdash;usually `dist` in CLI projects.

Patterns use a limited glob format:

Expand All @@ -38,7 +38,7 @@ Specifies the file that serves as the index page to satisfy navigation requests.

## `assetGroups`

*Assets* are resources that are part of the app version and they 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. Not all such external URLs may be known at build time; URL patterns can be matched.
*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.

This field contains an array of asset groups, each of which defines a set of asset resources and the policy by which they are cached.

Expand Down Expand Up @@ -71,13 +71,13 @@ interface AssetGroup {

### `name`

A `name` is mandatory. It is used to identify this particular group of assets between versions of the configuration.
A `name` is mandatory. It identifies this particular group of assets between versions of the configuration.

### `installMode`

The `installMode` determines how these resources are initially cached. The `installMode` can be either of two values:

* `prefetch` tells the Angular service worker to fetch every single listed resource that it can while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline.
* `prefetch` tells the Angular service worker to fetch every single listed resource while it's caching the current version of the app. This is bandwidth-intensive but ensures resources are available whenever they're requested, even if the browser is currently offline.

* `lazy` does not cache any of the resources up front. Instead, the Angular service worker only caches resources for which it receives requests. This is an on-demand caching mode. Resources that are never requested will not be cached. This is useful for things like images at different resolutions, so the service worker only caches the correct assets for the particular screen and orientation.

Expand All @@ -87,15 +87,15 @@ For resources already in the cache, the `updateMode` determines the caching beha

* `prefetch` tells the service worker to download and cache the changed resources immediately.

* `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`.
* `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`.

### `resources`

This section describes the resources to cache, broken up into three groups.

* `files` lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.

* `versionedFiles` is like `files`, but should be used for build artifacts that already include a hash in the filename, which is used for cache busting. The Angular service worker can optimize some aspects of its operation if it can assume file contents are immutable.
* `versionedFiles` is like `files` but should be used for build artifacts that already include a hash in the filename, which is used for cache busting. The Angular service worker can optimize some aspects of its operation if it can assume file contents are immutable.

* `urls` includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service.

Expand Down Expand Up @@ -126,11 +126,11 @@ Similar to `assetGroups`, every data group has a `name` which uniquely identifie
A list of URL patterns. URLs that match these patterns will be cached according to this data group's policy.

### `version`
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.
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.

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

`version` is an integer field, and it defaults to `0`.
`version` is an integer field and defaults to `0`.

### `cacheConfig`
This section defines the policy by which matching requests will be cached.
Expand All @@ -139,7 +139,7 @@ This section defines the policy by which matching requests will be cached.
(required) The maximum number of entries, or responses, in the cache. Open-ended caches can grow in unbounded ways and eventually exceed storage quotas, calling for eviction.

#### `maxAge`
(required) The `maxAge` paramter indicates how long responses are allowed to remain in the cache before being considered invalid and evicted. `maxAge` is a duration string, using the following unit suffixes:
(required) The `maxAge` parameter indicates how long responses are allowed to remain in the cache before being considered invalid and evicted. `maxAge` is a duration string, using the following unit suffixes:

* `d`: days
* `h`: hours
Expand Down

0 comments on commit c79275b

Please sign in to comment.