GoogleChrome / GoogleChrome/lighthouse

DBW: use navigator.sendBeacon in beforeunload/pagehide handlers

Open
#871 11 comments 1 reaction 0 assignees View on GitHub
needs-complete-audit-proposal new_audit P2
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 20h
Merged PRs (30d)
19

Description

How to check:
- look for `beforeunload`/`pagehide` handlers (can reuse https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/gatherers/dobetterweb/document-event-listeners.js)
- check for sync xhrs or `fetch` calls in the handler

> because user agents typically ignore asynchronous XMLHttpRequests made in an unload handler.

> To solve this problem, analytics and diagnostics code have historically made a synchronous XMLHttpRequest call in an unload or beforeunload event handler to submit the data. The synchronous XMLHttpRequest blocks the process of unloading the document, which in turn causes the next navigation appear to be slower. There is nothing the next page can do to avoid this perception of poor page load performance, and the result is that the user perceives that the new web page is slow to load, even though the true issue is with the previous page.

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.