htmx
htmx copied to clipboard
Combine polling and visibilitychange event
Think in most cases it makes no sense to poll if the browser tab is not visible, isn't it? e.g.: If the user will work with many tabs, then all tabs will create poll requests, but they may be useless because the update can only be seen on a visible browser tab ;)
It's possible to realize this today, e.g.:
hx-trigger="every 5s [document.visibilityState === 'visible'], visibilitychange[document.visibilityState === 'visible'] from:document"
This does:
- Stop polling if the page is not visible
- If the page changed from invisible to visible -> poll immediately
- If page stays visible -> poll periodically
Think it should be a easier way to do this.
See also discussion: https://github.com/bigskysoftware/htmx/discussions/821