GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.62k stars 331 forks source link

POST request not getting cached #218

Closed chiragmongia closed 7 years ago

chiragmongia commented 7 years ago

I want to cache a POST request for 5 minutes. My POST request entry looks like below-

toolbox.router.post(/myPostApi/, toolbox.cacheFirst, {
    cache: {
        name: 'myCache',
        maxAgeSeconds: 300
    }
});

This is not getting cached. The entries for GET requests in exact similar syntax are working fine. Am I missing something?

Garbee commented 7 years ago

Ref: W3C discussion on caching POST requests. Nothing in the toolbox is wrong, this just isn't allowed by the current specification.

Garbee commented 7 years ago

I think the best course here is to clarify in our docs that anything beyond GET or HEAD (if web browsers support HEAD) is capable of being cached. As browsers only really support POST otherwise and they are incapable of being cached currently.

chiragmongia commented 7 years ago

@Garbee Thanks! The w3c service worker discussion makes sense.