Performance
perf/bfcache-no-unload
No code listens to the unload event; use pagehide or visibilitychange so the page can use the back/forward cache.
moderatestaticfe-core-web-vitals
Why
With the back/forward cache, going back shows the page instantly with LCP, CLS and INP of a cached page. An unload listener makes Firefox skip the cache and Chrome is phasing the event out; unload also does not fire reliably on mobile, so the code it guards is lost anyway.
Fix
Move the work to pagehide (fires on every navigation away, cache or not) or to visibilitychange when document.visibilityState === 'hidden' (the last reliable moment on mobile). Send analytics with navigator.sendBeacon or fetch(…, { keepalive: true }). Check third-party scripts too: DevTools > Application > Back/forward cache lists what blocks it.
Examples
// bad
window.addEventListener('unload', sendStats)
// good
window.addEventListener('pagehide', sendStats)
document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'hidden') saveDraft() })Sources
Facts
- Id
perf/bfcache-no-unload- Severity
- moderate
- Check
- static checked in the source by
audit - Applies to
htmlvuesvelteastrojsx- Same problem in
- Lighthouse
bf-cache - Taught by the skill
fe-core-web-vitalsCore Web Vitals- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain perf/bfcache-no-unload