question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow post caching

See original GitHub issue

Library Affected: workbox-strategies

Browser & Platform: all browsers

Issue or Feature Request Description: Allow post caching

Developers should be able to cache post requests as get requests using cacheKeyWillBeUsed. Currently there is a check that prevents post caching, which checks the initial request instead of the request returned by cacheKeyWillBeUsed, which should be respected as a custom cache key.

A related issue #2574 was filed but closed by the author.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffposnickcommented, Oct 20, 2021

When using runtimeCaching in generateSW, you can specify custom plugins via the options.plugins array, along the lines of:

runtimeCaching: [{
  urlPattern: "https://pwa.test/post",
  method: "POST",
  handler: 'NetworkFirst',
  options: {
    cacheName: 'post',
    backgroundSync: {
      name: "myQueueName",
      options: {
        maxRetentionTime: 24 * 60
      },
    },
    plugins: [{
      cacheKeyWillBeUsed: () => {
        // You code to return a custom Request goes here.
      }
    }]
  },
}]
1reaction
jeffposnickcommented, Aug 28, 2020

I’ve merged your PR, and it will be in the next pre-release of v6.

I think it’s a good idea to perform the method check in the order in which your PR does it, but again, I don’t want to advertise this as “Workbox now supports caching POST requests.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to cache POST methods in HTTP? - Stack Overflow
So, YES, you can cache POST request response but only if it arrives with appropriate headers. In most cases you don't want to...
Read more >
HTTP caching - MDN Web Docs
The HTTP cache stores a response associated with a request and reuses the stored response for subsequent requests.
Read more >
Caching HTTP POST Requests and Responses
HTTP caching involves the client, the proxy, and the server. In this post, we will discuss mainly the proxy, which sits between the...
Read more >
Cache POST Responses - Akamai TechDocs
Enable caching of POST responses. How it works By default, POST requests are passed to the origin. With this behavior enabled, you can...
Read more >
Document Cache Policy with 'Cache Response to POST ... - IBM
You can enable the Cache Response to POST and PUT Requests option only when the Fixed caching policy type is selected. The Fixed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found