Can service workers cache POST requests?

前端 未结 5 1644
猫巷女王i
猫巷女王i 2020-12-01 04:30

I tried to cache a POST request in a service worker on fetch event.

I used cache.put(event.request, response), but the returned promise was rejected wit

5条回答
  •  无人及你
    2020-12-01 05:18

    You can't cache POST requests using the Cache API. See https://w3c.github.io/ServiceWorker/#cache-put (point 4).

    There's a related discussion in the spec repository: https://github.com/slightlyoff/ServiceWorker/issues/693

    An interesting solution is the one presented in the ServiceWorker Cookbook: https://serviceworke.rs/request-deferrer.html Basically, the solution serializes requests to IndexedDB.

提交回复
热议问题