Email or username:

Password:

Forgot your password?
Stefan Judis

With the upcoming Firefox 133 release `fetch` gets a new baseline-supported parameter — `keepalive`.

Requests with the set `keepalive` option won't be canceled when the page unloads or is closed. 💪

stefanjudis.com/today-i-learne

await fetch(`${root}/api/collect`, {
  method: 'POST',
  body: data,
  // keep request alive if the page is unloaded
  // before the request is complete
  keepalive: true,
});
6 comments
Sebbe

@stefan very nice. And about time FF got this in.

Alex Wilson

@stefan Interesting - is there a limit to the # of connections that can be kept alive?

Stefan Judis

@alexwilson That's a great question that I don't have the answer to. 😅 Why would the number of connections matter? I could only think of sending a few tracking beacons on session exit?

Alex Wilson

@stefan It's a very cool feature — a part of my mind immediately started wondering what happens if you queue up a large number of these on the page unload event... Added a note to my todo list to read the spec. 😅

micha

@stefan @rauschma so ohne can get tracked, even when the page/tab is closed? 🤔

Go Up