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
This commit is contained in:

committed by
Misko Hevery

parent
145ab3d7e0
commit
a2068523fd
@ -267,6 +267,12 @@ By default, these criteria are:
|
||||
1. The URL must not contain a file extension (i.e. a `.`) in the last path segment.
|
||||
2. The URL must not contain `__`.
|
||||
|
||||
<div class="alert is-helpful">
|
||||
|
||||
To configure whether navigation requests are sent through to the network or not, see the [navigationRequestStrategy](#navigation-request-strategy) section.
|
||||
|
||||
</div>
|
||||
|
||||
### Matching navigation request URLs
|
||||
|
||||
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:
|
||||
'!/**/*__*/**', // Exclude URLs containing `__` in any other segment.
|
||||
]
|
||||
```
|
||||
|
||||
{@a navigation-request-strategy}
|
||||
|
||||
## `navigationRequestStrategy`
|
||||
|
||||
This optional property enables you to configure how the service worker handles navigation requests:
|
||||
|
||||
```json
|
||||
{
|
||||
"navigationRequestStrategy": "freshness"
|
||||
}
|
||||
```
|
||||
|
||||
Possible values:
|
||||
|
||||
- `'performance'`: The default setting. Serves the specified [index file](#index-file), which is typically cached.
|
||||
- `'freshness'`: Passes the requests through to the network and falls back to the `performance` behavior when offline.
|
||||
This value is useful when the server redirects the navigation requests elsewhere using an HTTP redirect (3xx status code).
|
||||
Reasons for using this value include:
|
||||
- Redirecting to an authentication website when authentication is not handled by the application.
|
||||
- Redirecting specific URLs to avoid breaking existing links/bookmarks after a website redesign.
|
||||
- Redirecting to a different website, such as a server-status page, while a page is temporarily down.
|
||||
|
||||
<div class="alert is-important">
|
||||
|
||||
The `freshness` strategy usually results in more requests sent to the server, which can increase response latency.
|
||||
It is recommended that you use the default performance strategy whenever possible.
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user