Comparison
Page visibilityvsBeacon
Page visibility
you stopped the polling when the tab went to the background and started it again when it came back.
An event and property telling you whether the page is currently visible, which is how you avoid doing work for a tab nobody is looking at. It is also the reliable place to flush state before the page goes away, because `visibilitychange` to hidden is the last event guaranteed to fire on mobile. `unload` and `beforeunload` are not reliable and disable the back-forward cache into the bargain.
Full entry →Beacon
you sent the analytics event on page unload and it actually arrived, instead of being cancelled.
A small request the browser promises to deliver even after the page goes away, via `navigator.sendBeacon` or `fetch` with `keepalive`. It exists because unload handlers are the one place a normal request is routinely killed mid-flight. The payload limit is small, the method is POST, and you get no response back, so it is for telemetry and nothing else.
Full entry →