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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -