You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aio/content/guide/app-shell.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -87,4 +87,4 @@ Or to use the production configuration.
87
87
ng run my-app:app-shell:production
88
88
</code-example>
89
89
90
-
To verify the build output, open `dist/my-app/browser/index.html`. Look for default text `app-shell works!` to show that the application shell route was rendered as part of the output.
90
+
To verify the build output, open <codeclass="no-auto-link">dist/my-app/browser/index.html</code>. Look for default text `app-shell works!` to show that the application shell route was rendered as part of the output.
Copy file name to clipboardExpand all lines: aio/content/guide/service-worker-communications.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ For example, imagine the following scenario:
77
77
This newer version includes the files `index.html`, `main.<main-hash-2>.js` and `lazy-chunk.<lazy-hash-2>.js` (note that the hashes are different now, because the content of the files has changed).
78
78
The old version is no longer available on the server.
79
79
- In the meantime, the user's browser decides to evict `lazy-chunk.<lazy-hash-1>.js` from its cache.
80
-
Browsers may decide to evict specific (or all) resources from a cache in order to reclaim disk space.
80
+
This is possible since browsers may decide to evict specific (or all) resources from a cache in order to reclaim disk space.
81
81
- The user opens the application again.
82
82
The service worker serves the latest version known to it at this point, namely the old version (`index.html` and `main.<main-hash-1>.js`).
83
83
- At some later point, the application requests the lazy bundle, `lazy-chunk.<lazy-hash-1>.js`.
@@ -87,7 +87,7 @@ For example, imagine the following scenario:
87
87
In the above scenario, the service worker is not able to serve an asset that would normally be cached.
88
88
That particular application version is broken and there is no way to fix the state of the client without reloading the page.
89
89
In such cases, the service worker notifies the client by sending an `UnrecoverableStateEvent` event.
90
-
You can subscribe to `SwUpdate#unrecoverable` to be notified and handle these errors.
90
+
You can subscribe to `SwUpdate.unrecoverable` to be notified and handle these errors.
Copy file name to clipboardExpand all lines: aio/content/guide/service-worker-getting-started.md
+32-25Lines changed: 32 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ A basic understanding of the information in [Introduction to Angular service wor
10
10
11
11
## Adding a service worker to your project
12
12
13
-
To set up the Angular service worker in your project, use the CLI command `ng add @angular/pwa`. It takes care of configuring your application to use service workers by adding the `service-worker` package along
13
+
To set up the Angular service worker in your project, use the CLI command `ng add @angular/pwa`. It takes care of configuring your application to use service workers by adding the `@angular/service-worker` package along
14
14
with setting up the necessary support files.
15
15
16
16
```sh
@@ -24,7 +24,7 @@ The above command completes the following actions:
24
24
3. Imports and registers the service worker in the application module.
25
25
4. Updates the `index.html` file:
26
26
* Includes a link to add the `manifest.webmanifest` file.
27
-
* Adds meta tags for `theme-color`.
27
+
* Adds a meta tag for `theme-color`.
28
28
5. Installs icon files to support the installed Progressive Web App (PWA).
29
29
6. Creates the service worker configuration file called [`ngsw-config.json`](/guide/service-worker-config), which specifies the caching behaviors and other settings.
With the server running, you can point your browser at http://localhost:8080/. Your application should load normally.
58
+
With the server running, you can point your browser at [http://localhost:8080](http://localhost:8080). Your application should load normally.
59
+
60
+
<divclass="alert is-helpful">
59
61
60
62
**Tip:** When testing Angular service workers, it's a good idea to use an incognito or private window in your browser to ensure the service worker doesn't end up reading from a previous leftover state, which can cause unexpected behavior.
61
63
64
+
</div>
65
+
62
66
<divclass="alert is-helpful">
63
67
64
68
**Note:**
@@ -68,14 +72,16 @@ If you are not using HTTPS, the service worker will only be registered when acce
68
72
69
73
### Simulating a network issue
70
74
71
-
To simulate a network issue, disable network interaction for your application. In Chrome:
75
+
To simulate a network issue, disable network interaction for your application.
76
+
77
+
In Chrome:
72
78
73
79
1. Select **Tools** > **Developer Tools** (from the Chrome menu located at the top right corner).
74
-
2. Go to the **Network tab**.
75
-
3. Check the **Offline box**.
80
+
1. Go to the **Network tab**.
81
+
1. Select **Offline** in the **Throttling** dropdown menu.
76
82
77
83
<divclass="lightbox">
78
-
<imgsrc="generated/images/guide/service-worker/offline-checkbox.png"alt="The offline checkbox in the Network tab is checked">
84
+
<imgsrc="generated/images/guide/service-worker/offline-option.png"alt="The offline option in the Network tab is selected">
79
85
</div>
80
86
81
87
Now the application has no access to network interaction.
@@ -90,7 +96,7 @@ If you look at the Network tab, you can verify that the service worker is active
90
96
<imgsrc="generated/images/guide/service-worker/sw-active.png"alt="Requests are marked as from ServiceWorker">
91
97
</div>
92
98
93
-
Notice that under the "Size" column, the requests state is `(from ServiceWorker)`. This means that the resources are not being loaded from the network. Instead, they are being loaded from the service worker's cache.
99
+
Notice that under the "Size" column, the requests state is `(ServiceWorker)`. This means that the resources are not being loaded from the network. Instead, they are being loaded from the service worker's cache.
94
100
95
101
96
102
### What's being cached?
@@ -104,7 +110,7 @@ Notice that all of the files the browser needs to render this application are ca
104
110
* Images and fonts directly under the configured `outputPath` (by default `./dist/<project-name>/`) or `resourcesOutputPath`. See [`ng build`](cli/build) for more information about these options.
105
111
106
112
107
-
<divclass="alert is-helpful">
113
+
<divclass="alert is-important">
108
114
Pay attention to two key points:
109
115
110
116
1. The generated `ngsw-config.json` includes a limited list of cacheable fonts and images extensions. In some cases, you might want to modify the glob pattern to suit your needs.
@@ -119,15 +125,15 @@ next step is understanding how updates work. Let's make a change to the applicat
119
125
120
126
1. If you're testing in an incognito window, open a second blank tab. This will keep the incognito and the cache state alive during your test.
121
127
122
-
2. Close the application tab, but not the window. This should also close the Developer Tools.
128
+
1. Close the application tab, but not the window. This should also close the Developer Tools.
123
129
124
-
3. Shut down `http-server`.
130
+
1. Shut down `http-server`.
125
131
126
-
4. Open `src/app/app.component.html` for editing.
132
+
1. Open `src/app/app.component.html` for editing.
127
133
128
-
5. Change the text `Welcome to {{title}}!` to `Bienvenue à {{title}}!`.
134
+
1. Change the text `Welcome to {{title}}!` to `Bienvenue à {{title}}!`.
Now look at how the browser and service worker handle the updated application.
140
146
141
-
1. Open http://localhost:8080 again in the same window. What happens?
147
+
1. Open [http://localhost:8080](http://localhost:8080) again in the same window. What happens?
142
148
143
-
<divclass="lightbox">
144
-
<imgsrc="generated/images/guide/service-worker/welcome-msg-en.png"alt="It still says Welcome to Service Workers!">
145
-
</div>
149
+
<divclass="lightbox">
150
+
<img src="generated/images/guide/service-worker/welcome-msg-en.png" alt="It still says Welcome to Service Workers!">
151
+
</div>
146
152
147
-
What went wrong? Nothing, actually. The Angular service worker is doing its job and serving the version of the application that it has **installed**, even though there is an update available. In the interest of speed, the service worker doesn't wait to check for updates before it serves the application that it has cached.
153
+
What went wrong? Nothing, actually. The Angular service worker is doing its job and serving the version of the application that it has **installed**, even though there is an update available. In the interest of speed, the service worker doesn't wait to check for updates before it serves the application that it has cached.
148
154
149
-
If you look at the `http-server` logs, you can see the service worker requesting `/ngsw.json`. This is how the service worker checks for updates.
155
+
If you look at the `http-server` logs, you can see the service worker requesting `/ngsw.json`. This is how the service worker checks for updates.
150
156
151
-
2. Refresh the page.
157
+
1. Refresh the page.
152
158
153
-
<divclass="lightbox">
154
-
<imgsrc="generated/images/guide/service-worker/welcome-msg-fr.png"alt="The text has changed to say Bienvenue à app!">
155
-
</div>
159
+
<divclass="lightbox">
160
+
<img src="generated/images/guide/service-worker/welcome-msg-fr.png" alt="The text has changed to say Bienvenue à app!">
161
+
</div>
156
162
157
-
The service worker installed the updated version of your application *in the background*, and the next time the page is loaded or reloaded, the service worker switches to the latest version.
163
+
The service worker installed the updated version of your application *in the background*, and the next time the page is loaded or reloaded, the service worker switches to the latest version.
158
164
159
165
## More on Angular service workers
160
166
161
167
You may also be interested in the following:
168
+
*[App Shell](guide/app-shell).
162
169
*[Communicating with service workers](guide/service-worker-communications).
Copy file name to clipboardExpand all lines: aio/content/guide/service-worker-intro.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -17,25 +17,25 @@ Angular applications, as single-page applications, are in a prime position to be
17
17
18
18
Angular's service worker is designed to optimize the end user experience of using an application over a slow or unreliable network connection, while also minimizing the risks of serving outdated content.
19
19
20
-
The Angular service worker's behavior follows that design goal:
20
+
To achieve this, the Angular service workerfollows these guidelines:
21
21
22
22
* Caching an application is like installing a native application. The application is cached as one unit, and all files update together.
23
23
* A running application continues to run with the same version of all files. It does not suddenly start receiving cached files from a newer version, which are likely incompatible.
24
24
* When users refresh the application, they see the latest fully cached version. New tabs load the latest cached code.
25
25
* Updates happen in the background, relatively quickly after changes are published. The previous version of the application is served until an update is installed and ready.
26
26
* The service worker conserves bandwidth when possible. Resources are only downloaded if they've changed.
27
27
28
-
To support these behaviors, the Angular service worker loads a *manifest* file from the server. The manifest describes the resources to cache and includes hashes of every file's contents. When an update to the application is deployed, the contents of the manifest change, informing the service worker that a new version of the application should be downloaded and cached. This manifest is generated from a CLI-generated configuration file called `ngsw-config.json`.
28
+
To support these behaviors, the Angular service worker loads a *manifest* file from the server. The file, called `ngsw.json` (not to be confused with the [web app manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest)), describes the resources to cache and includes hashes of every file's contents. When an update to the application is deployed, the contents of the manifest change, informing the service worker that a new version of the application should be downloaded and cached. This manifest is generated from a CLI-generated configuration file called `ngsw-config.json`.
29
29
30
30
Installing the Angular service worker is as easy as including an `NgModule`. In addition to registering the Angular service worker with the browser, this also makes a few services available for injection which interact with the service worker and can be used to control it. For example, an application can ask to be notified when a new update becomes available, or an application can ask the service worker to check the server for available updates.
31
31
32
32
## Prerequisites
33
33
34
-
To make use of all the features of Angular service worker, use the latest versions of Angular and the Angular CLI.
34
+
To make use of all the features of Angular service workers, use the latest versions of Angular and the Angular CLI.
35
35
36
36
In order for service workers to be registered, the application must be accessed over HTTPS, not HTTP.
37
37
Browsers ignore service workers on pages that are served over an insecure connection.
38
-
The reason is that service workers are quite powerful, so extra care needs to be taken to ensure the service worker script has not been tampered with.
38
+
The reason is that service workers are quite powerful, so extra care is needed to ensure the service worker script has not been tampered with.
39
39
40
40
There is one exception to this rule: to make local development easier, browsers do _not_ require a secure connection when accessing an application on `localhost`.
41
41
@@ -48,7 +48,7 @@ Browsers like IE and Opera Mini do not support service workers.
48
48
If the user is accessing your application with a browser that does not support service workers, the service worker is not registered and related behavior such as offline cache management and push notifications does not happen.
49
49
More specifically:
50
50
51
-
* The browser does not download the service worker script and `ngsw.json` manifest file.
51
+
* The browser does not download the service worker script and the `ngsw.json` manifest file.
52
52
* Active attempts to interact with the service worker, such as calling `SwUpdate.checkForUpdate()`, return rejected promises.
53
53
* The observable events of related services, such as `SwUpdate.available`, are not triggered.
0 commit comments