mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(service-worker): mention strategy-dependent caching behavior for opaque responses (#44723)
Update the "Service worker configuration" guide to mention the different caching behaviors used for opaque responses based on the data-group's configured strategy. Related to #44246. PR Close #44723
This commit is contained in:
committed by
Andrew Kushnir
parent
531d1cf9a3
commit
2f1457d12f
@@ -247,6 +247,28 @@ This essentially does the following:
|
||||
|
||||
</div>
|
||||
|
||||
<div class="callout is-important">
|
||||
|
||||
<header>Note on opaque responses</header>
|
||||
|
||||
[Opaque responses][opaque-response] are handled differently depending on the used strategy:
|
||||
Data-groups with the `freshness` strategy cache such responses normally.
|
||||
Data-groups with the `performance` strategy, however, do not cache opaque responses.
|
||||
|
||||
In case you are not familiar, an opaque response is a special type of response returned when requesting a resource that is on a different origin which doesn't return CORS headers.
|
||||
One of the characteristics of an opaque response is that the service worker is not allowed to read its status, meaning it can't check if the request was successful or not.
|
||||
See [Introduction to fetch()][response-types] for more details.
|
||||
|
||||
For data-groups with the `freshness` strategy, it doesn't matter if the service worker caches an error response.
|
||||
The data will be requested anew every time, only falling back to the cached response when offline or on a slow network.
|
||||
|
||||
For data-groups with the `performance` strategy on the other hand, caching an error response would be quite problematic.
|
||||
The service worker would continue to serve the error response until `maxAge` expired, even if the error was due to a temporary network or server issue.
|
||||
|
||||
If you are not able to implement CORS—for example, if you don't control the origin—prefer using the `freshness` strategy for resources that result in opaque responses.
|
||||
|
||||
</div>
|
||||
|
||||
### `cacheQueryOptions`
|
||||
|
||||
See [assetGroups](#assetgroups) for details.
|
||||
@@ -320,4 +342,8 @@ Possible values:
|
||||
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>
|
||||
</div>
|
||||
|
||||
|
||||
[opaque-response]: https://fetch.spec.whatwg.org/#concept-filtered-response-opaque
|
||||
[response-types]: https://developers.google.com/web/updates/2015/03/introduction-to-fetch#response_types
|
||||
|
||||
Reference in New Issue
Block a user