navigator.sendBeacon() sends a small async HTTP POST for analytics without blocking the next page. Learn the boolean return value, visibilitychange best practice, the ~64 KiB limit, five examples, and try-it labs.
01
Kind
Method
02
Returns
boolean
03
Status
Baseline Widely available
04
HTTP
POST only
05
Size limit
~64 KiB queued
06
Best trigger
visibilitychange
Fundamentals
Introduction
Analytics often need to fire when the user leaves a page. Old tricks used synchronous XMLHttpRequest or delayed unload with image beacons — and made the next page feel slow.
sendBeacon(url, data) queues a small POST that the browser can finish in the background. Navigation stays snappy, and you still get a reliable chance to log the event.
💡
No Dep / Exp / Non-standard banner
MDN marks Baseline Widely available (since April 2018). Prefer visibilitychange over unload / beforeunload.
Concept
Understanding the sendBeacon() Method
URL required — relative or absolute endpoint that accepts POST.
Data optional — string, Blob, FormData, URLSearchParams, buffers, etc.
Returns boolean — true if queued, false if not.
No response body — you cannot read the server reply (use fetch if you need it).
~64 KiB limit — keep payloads small.
Does not block unload — designed for end-of-session analytics.
Four facts to remember about navigator.sendBeacon().
Returns
boolean
Queued?
Status
Baseline
Widely available
Method
POST
Beacon API
Limit
~64KiB
Keep it small
Compare
📋 sendBeacon vs fetch keepalive
sendBeacon()
fetch(..., { keepalive: true })
HTTP method
POST only
Any method you set
Custom headers
Limited / not the goal
Full control
Read response
No
Yes (when the request completes)
Best for
Simple analytics pings
Richer unload requests
Hands-On
Examples Gallery
Examples queue beacons to demo endpoints. In Try It Yourself, use a path on the same origin or a public test URL — the important part is the boolean queue result and the visibilitychange pattern.
navigator.sendBeacon() is Baseline Widely available across modern browsers (MDN: since April 2018). Use it for small analytics POSTs, especially on visibilitychange. For larger payloads or custom methods/headers, prefer fetch with keepalive: true.
✓ Baseline · Widely available
Navigator.sendBeacon()
Async analytics POST that does not block the next navigation.
UniversalWidely available
Google ChromeBeacon API · modern versions
Full support
Mozilla FirefoxBeacon API · modern versions
Full support
Microsoft EdgeBeacon API · Chromium
Full support
Apple SafariBeacon API · modern versions
Full support
OperaBeacon API · modern versions
Full support
Internet ExplorerNo modern sendBeacon — use a fallback
Unavailable
sendBeacon()Excellent
Bottom line: Detect the method, keep payloads small, fire on visibility hidden, check the boolean queue result, and fall back to fetch keepalive when needed.
Wrap Up
Conclusion
navigator.sendBeacon() is the Baseline way to ship tiny analytics POSTs without slowing the next page. Trigger it on visibilitychange, keep payloads small, and treat the return value as “queued,” not “server confirmed.”
Baseline analytics POST — queue small data without blocking navigation.
5
Core concepts
📡01
Sends
async POST
Beacon
✅02
Status
Baseline
Widely available
👁03
Trigger
visibilitychange
hidden
📏04
Limit
~64 KiB
Small payloads
📈05
Returns
queued?
boolean
❓ Frequently Asked Questions
It queues a small HTTP POST request to a URL, typically for analytics. The browser sends it asynchronously without blocking page unload or the next navigation.
No. MDN marks it Baseline Widely available (since April 2018). It is not Deprecated, Experimental, or Non-standard — no status banner is required.
A common pattern is on visibilitychange when document.visibilityState becomes "hidden" — more reliable than unload or beforeunload, especially on mobile.
true means the user agent successfully queued the data for transfer. false means it could not queue it (for example the payload is too large or the browser refused).
Queued data is limited to about 64 KiB (65,536 bytes). For larger transfers or custom methods/headers/response access, use fetch() with keepalive: true.
Optional data can be a string, Blob, FormData, URLSearchParams, ArrayBuffer, TypedArray, or DataView.
Did you know?
Pages that register unload handlers can be excluded from the browser’s back/forward cache. That is one more reason MDN recommends visibilitychange + sendBeacon() for leave-time analytics.