Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Oct 29, 2025 · Frontend Development

Mastering the visibilitychange Event: Detect and React to Page Visibility Changes

This article explains the native visibilitychange event of the Page Visibility API, its core properties document.hidden and document.visibilityState, provides complete JavaScript examples for listening and removing the event, discusses practical use cases such as media control, request throttling, form saving, outlines browser compatibility, and highlights limitations and best‑practice considerations.

JavaScriptPage Visibility APIbrowser events
0 likes · 16 min read
Mastering the visibilitychange Event: Detect and React to Page Visibility Changes
JavaScript
JavaScript
Jul 11, 2025 · Frontend Development

Make JavaScript Polling Smarter: From setInterval to Adaptive Strategies

This article examines the inefficiencies of traditional setInterval polling and presents three intelligent alternatives—using recursive setTimeout, applying exponential backoff, and leveraging the Page Visibility API—while providing code samples and highlighting their benefits over naive polling.

JavaScriptPage Visibility APIPolling
0 likes · 6 min read
Make JavaScript Polling Smarter: From setInterval to Adaptive Strategies