fetch keepalive
A fetch option, keepalive: true, that lets a small request keep going after the page that started it has been closed or navigated away.
In more detail
It is the modern way to send analytics on page exit, replacing navigator.sendBeacon() while allowing any method and headers. The total body size of pending keepalive requests is limited to 64 kilobytes.
Example
fetch('/analytics', { method: 'POST', body, keepalive: true })Related terms
- navigator.sendBeacon() — A browser function that queues a small POST request to be sent reliably even while the page is unloading.
- page unload — The moment a page is being closed or navigated away from, when ordinary requests may be cancelled.
- telemetry — The data a running system sends out about itself, such as logs, metrics and traces.
- Fetch API — The standard JavaScript function fetch() for making HTTP requests, built into browsers and current server runtimes, which returns a promise for the response.
Taught in
- The Fetch API: Streaming Responses, HTTP Caching And Keepalive — Frontend Architecture & Web Platform