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
feat(service-worker): add the option to prefer network for navigation requests (#38565)
This commit introduces a new option for the service worker, called
`navigationRequestStrategy`, which adds the possibility to force the service worker
to always create a network request for navigation requests.
This enables the server redirects while retaining the offline behavior.
Fixes#38194
PR Close#38565
Copy file name to clipboardExpand all lines: aio/content/guide/service-worker-config.md
+35
Original file line number
Diff line number
Diff line change
@@ -267,6 +267,12 @@ By default, these criteria are:
267
267
1. The URL must not contain a file extension (i.e. a `.`) in the last path segment.
268
268
2. The URL must not contain `__`.
269
269
270
+
<divclass="alert is-helpful">
271
+
272
+
To configure whether navigation requests are sent through to the network or not, see the [navigationRequestStrategy](#navigation-request-strategy) section.
273
+
274
+
</div>
275
+
270
276
### Matching navigation request URLs
271
277
272
278
While these default criteria are fine in most cases, it is sometimes desirable to configure different rules. For example, you may want to ignore specific routes (that are not part of the Angular app) and pass them through to the server.
@@ -285,3 +291,32 @@ If the field is omitted, it defaults to:
285
291
'!/**/*__*/**', // Exclude URLs containing `__` in any other segment.
286
292
]
287
293
```
294
+
295
+
{@a navigation-request-strategy}
296
+
297
+
## `navigationRequestStrategy`
298
+
299
+
This optional property enables you to configure how the service worker handles navigation requests:
300
+
301
+
```json
302
+
{
303
+
"navigationRequestStrategy": "freshness"
304
+
}
305
+
```
306
+
307
+
Possible values:
308
+
309
+
-`'performance'`: The default setting. Serves the specified [index file](#index-file), which is typically cached.
310
+
-`'freshness'`: Passes the requests through to the network and falls back to the `performance` behavior when offline.
311
+
This value is useful when the server redirects the navigation requests elsewhere using an HTTP redirect (3xx status code).
312
+
Reasons for using this value include:
313
+
- Redirecting to an authentication website when authentication is not handled by the application.
314
+
- Redirecting specific URLs to avoid breaking existing links/bookmarks after a website redesign.
315
+
- Redirecting to a different website, such as a server-status page, while a page is temporarily down.
316
+
317
+
<divclass="alert is-important">
318
+
319
+
The `freshness` strategy usually results in more requests sent to the server, which can increase response latency.
320
+
It is recommended that you use the default performance strategy whenever possible.
Copy file name to clipboardExpand all lines: packages/service-worker/config/schema.json
+8
Original file line number
Diff line number
Diff line change
@@ -161,6 +161,14 @@
161
161
"type": "string"
162
162
},
163
163
"uniqueItems": true
164
+
},
165
+
"navigationRequestStrategy": {
166
+
"enum": [
167
+
"freshness",
168
+
"performance"
169
+
],
170
+
"default": "performance",
171
+
"description": "The Angular service worker can use two request strategies for navigation requests. 'performance', the default, skips navigation requests. The other strategy, 'freshness', forces all navigation requests through the network."
0 commit comments