Skip to content

[documentation]: explain keepalive #780

Closed

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 :)

Activity

  1. JakeChampion commented on Jun 4, 2020

    @JakeChampion
    Owner

    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)

  2. locked as resolved and limited conversation to collaborators on Jan 7, 2021
  3. added a commit that references this issue on Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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