Supporting ETag and if-none-match #1388
Replies: 3 comments
-
@RobertGardner Have you found any solution to this? I'm struggling to figure out how to use refreshInterval without sending all of the data back each time if I know the client has the latest. Does anyone have a suggestion for that? |
Beta Was this translation helpful? Give feedback.
-
I ended up implementing a custom fetcher that implemented the ETag logic. Not the greatest but it worked and wasn’t very hard. Unfortunately, I no longer work at that company so I can’t access the code to provide more details. |
Beta Was this translation helpful? Give feedback.
-
My server sends The issue: When I checked the network requests in the browser, I saw etags coming back but no if-none-match header was ever sent on subsequent requests, even though browsers should handle etags automatically. Solution: In the end, it turned out the issue was that in my fetcher a content-type header was being set even for GET requests. This prevents the browser from automatically handling etags it appears. After removing the unnecessary content-type header for the GET requests, etag was handled automatically by the browser. In my swr fetcher I only returned undefined when receiving a 304 code to be sure (but it seems to never land there anyway). No need to implement custom etag handling with swr 🥳 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
My server supports ETag and if-none-match on some requests with large payloads, but SWR doesn't seem to pay attention to these out-of-the-box. What is the suggested technique for supporting these?
Beta Was this translation helpful? Give feedback.
All reactions