Can Axios be configured to keep requests alive after a browser page is closed? Native fetch() accepts keepalive flag to enable this functionality, while I haven't found any similar in Axios documentation.
keepalive The keepalive option can be used to allow the request to outlive the page. Fetch with the keepalive flag is a replacement for the Navigator.sendBeacon() API.
https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
Yes you can do this with axios if you create your own axios instance.
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'},
httpAgent: new http.Agent({ keepAlive: true }),
});
Axios docs can guide you a bit more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With