While researching fetch polyfills, I found the keepalive option, which indicates that the request may outlive the current page context.
As a library author, I'm looking for good ways to rely on fetch support (polyfilled or not) so that my library can send data. I wanted to check what happens when a polyfill is applied and keepalive is provided (either true or false), because in the event that keepalive: true is set, I do not want the polyfilled code to send a synchronous XHR request and penalize UX.
Since this is a very widely adopted polyfill, I wanted to understand how it handles keepalive (if at all) but I could not find any documentation.
I assume that because the underlying keepalive connection is handled in the background, the polyfill cannot do anything about it and thus, in the case of keepalive: true, the connection is terminated by the browser as the page context is close and the request is not sent synchronously.
In pseudo code, I want to know if should check for fetch support via
if(fetch.toString().indexOf("[native code]")>-1){fetch({...,keepalive: true})// we can be sure this will never be synchronous}
vs
if(typeoffetch==="function"{fetch({...,keepalive: true})// this might be sync, depending on the polyfill}
I realize that there can be many different polyfills with varying implementations and it might be always best to rely on native code implementation in my case, but whatever the case, I would love to help you add a paragraph or two to the documentation at least for people to know how keepalive is supported via this polyfill :)
The text was updated successfully, but these errors were encountered:
Yes, we are more than happy for someone to contribute documentation on this. We do not offer keepalive because we do not want to add synchronous XHR to this polyfill. Here is a previous discussion on this (Before I was a maintainer on this project) -- #700 (comment)
JonasBa commentedJun 4, 2020
•
edited
While researching fetch polyfills, I found the keepalive option, which indicates that the request may outlive the current page context.
As a library author, I'm looking for good ways to rely on fetch support (polyfilled or not) so that my library can send data. I wanted to check what happens when a polyfill is applied and keepalive is provided (either true or false), because in the event that
keepalive: trueis set, I do not want the polyfilled code to send a synchronous XHR request and penalize UX.Since this is a very widely adopted polyfill, I wanted to understand how it handles keepalive (if at all) but I could not find any documentation.
I assume that because the underlying keepalive connection is handled in the background, the polyfill cannot do anything about it and thus, in the case of
keepalive: true, the connection is terminated by the browser as the page context is close and the request is not sent synchronously.In pseudo code, I want to know if should check for fetch support via
vs
I realize that there can be many different polyfills with varying implementations and it might be always best to rely on native code implementation in my case, but whatever the case, I would love to help you add a paragraph or two to the documentation at least for people to know how keepalive is supported via this polyfill :)
The text was updated successfully, but these errors were encountered: