Skip to content

Emulate the keepalive option by doing a synchronous request #700

Closed
@alexturpin

Description

@alexturpin

Historically, when sending data from browsers to server before the page is closed (e.g. through the beforeunload event), XHR synchronous requests have been used.

This is now deprecated in Chrome, with likely more browsers to follow. The prescribed solution is either navigator.sendBeacon (which only works for POST) or fetch with a keepalive flag.

It's not possible to properly polyfill the keepalive flag of course, but sending a synchronous XHR request is a good alternative for older browsers. Would you guys accept a PR that makes synchronous requests when the keepalive flag is set to true, with corresponding documentation in the README? This would make it so that people could use a single API call to support keepalive requests on beforeunload, instead of having to do lots of code branching.

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