mayu-live / framework

Mayu is a live updating server-side component-based VDOM rendering framework written in Ruby
https://mayu.live
GNU Affero General Public License v3.0
135 stars 4 forks source link

Slow down updates when tab is in background #36

Open aalin opened 1 year ago

aalin commented 1 year ago

Listen to the visibilitychange-event and notify the server when it happens.

Pseudo-code:

document.addEventListener("visibilitychange", () => {
  postCallback(sessionId, "visibilitychange", document.visibilityState);
});

And then on the server, the session could reduce the rate of updates, maybe do them once per second, or maybe even wait a longer time if the tab has been left in the background for a while.

This would reduce server load and network traffic when tabs are left in the background.