Can service workers cache POST requests?

前端 未结 5 1622
猫巷女王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:14

    Another approach to provide a full offline experience can be obtained by using Cloud Firestore offline persistence.

    POST / PUT requests are executed on the local cached database and then automatically synchronised to the server as soon as the user restores its internet connectivity (note though that there is a limit of 500 offline requests).

    Another aspect to be taken into account by following this solution is that if multiple users have offline changes that get concurrently synchronised, there is no warranty that the changes will be executed in the right chronological order on the server as Firestore uses a first come first served logic.

提交回复
热议问题