Skip to content

[documentation]: explain keepalive #780

@JonasBa

Description

@JonasBa

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(typeof fetch === "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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions