cacheOkAndOpaquePlugin.js 677 B

1234567891011121314151617181920212223242526
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. export const cacheOkAndOpaquePlugin = {
  9. /**
  10. * Returns a valid response (to allow caching) if the status is 200 (OK) or
  11. * 0 (opaque).
  12. *
  13. * @param {Object} options
  14. * @param {Response} options.response
  15. * @return {Response|null}
  16. *
  17. * @private
  18. */
  19. cacheWillUpdate: async ({ response }) => {
  20. if (response.status === 200 || response.status === 0) {
  21. return response;
  22. }
  23. return null;
  24. },
  25. };