angular-cn/packages/service-worker
Maximilian Koeller ee35e223a7 feat(service-worker): use `ignoreVary: true` when retrieving responses from cache (#34663)
The Angular ServiceWorker always uses a copy of the request without
headers for caching assets (in order to avoid issues with opaque
responses). Therefore, it was previously not possible to retrieve
resources from the cache if the response contained [Vary](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) headers.

In addition to that, `Vary` headers do not work in all browsers (or work
differently) and may not work as intended with ServiceWorker caches. See
[this article](https://www.smashingmagazine.com/2017/11/understanding-vary-header) and the linked resources for more info.

This commit avoids the aforementioned issues by making sure the Angular
ServiceWorker always sets the `ignoreVary` option passed to
[Cache#match()](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match) to `true`. This allows the ServiceWorker to correctly
retrieve cached responses with `Vary` headers, which was previously not
possible.

Fixes #36638

BREAKING CHANGE:

Previously, [Vary](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary)
headers would be taken into account when retrieving resources from the
cache, completely preventing the retrieval of cached assets (due to
ServiceWorker implementation details) and leading to unpredictable
behavior due to inconsistent/buggy implementations in different
browsers.

Now, `Vary` headers are ignored when retrieving resources from the
ServiceWorker caches, which can result in resources being retrieved even
when their headers are different. If your application needs to
differentiate its responses based on request headers, please make sure
the Angular ServiceWorker is [configured](https://angular.io/guide/service-worker-config)
to avoid caching the affected resources.

PR Close #34663
2020-05-01 09:44:07 -07:00
..
cli build: reformat repo to new clang@1.4.0 (#36613) 2020-04-14 12:08:36 -07:00
config feat(service-worker): use `ignoreVary: true` when retrieving responses from cache (#34663) 2020-05-01 09:44:07 -07:00
src build: reformat repo to new clang@1.4.0 (#36613) 2020-04-14 12:08:36 -07:00
test feat(service-worker): use `ignoreVary: true` when retrieving responses from cache (#34663) 2020-05-01 09:44:07 -07:00
testing build: reformat repo to new clang@1.4.0 (#36613) 2020-04-14 12:08:36 -07:00
worker feat(service-worker): use `ignoreVary: true` when retrieving responses from cache (#34663) 2020-05-01 09:44:07 -07:00
BUILD.bazel build: provide full paths to `ts_api_guardian_test_npm_package` and `ts_api_guardian_test` (#36034) 2020-03-12 09:49:00 -07:00
PACKAGE.md docs: add package doc files (#26047) 2018-10-05 15:42:14 -07:00
index.ts fix(aio): add service worker entrypoint to aio build (#19875) 2017-10-23 19:31:42 -04:00
package.json build(packaging): add repository.directory field to package.jsons (#27544) 2020-02-25 13:12:45 -08:00
public_api.ts feat(service-worker): introduce the @angular/service-worker package (#19274) 2017-09-28 16:18:12 -07:00
safety-worker.js build: reformat repo to new clang@1.4.0 (#36613) 2020-04-14 12:08:36 -07:00