javascript - Can service workers cache POST requests? -
i tried cache post request in service worker on fetch event.
i used cache.put(event.request, response)
, returned promise rejected typeerror: invalid request method post.
.
when tried hit same post api, caches.match(event.request)
giving me undefined.
but when did same methods, worked: caches.match(event.request)
request giving me response.
can service workers cache post requests? in case can't, approach can use make apps offline?
you can't cache post requests using cache api. see https://slightlyoff.github.io/serviceworker/spec/service_worker/#cache-put-method (point 2.2).
there's related discussion in spec repository: https://github.com/slightlyoff/serviceworker/issues/693
an interesting solution 1 presented in serviceworker cookbook: https://serviceworke.rs/request-deferrer.html basically, solution serializes requests indexeddb.
Comments
Post a Comment