Page should not refresh when it's in background #75

Closed
opened 2024-09-01 19:56:14 +02:00 by liquidev · 2 comments
liquidev commented 2024-09-01 19:56:14 +02:00 (Migrated from github.com)

Sometimes I notice that on my testing instance, which is behind an nginx proxy, the page refreshes in the background. This is because nginx closes the connection after a certain period of inactivity—not receiving a WebSocket ping.

My theory is that browsers stop sending pings once a tab is unfocused, which causes nginx to reap the connection after some time.

This is fine and expected, but it causes the frontend to refresh even when the app is inactive. This can cause unnecessary requests to the server despite the user being inactive. We should only attempt to refresh the page once the user focuses the tab again.

Sometimes I notice that on my testing instance, which is behind an nginx proxy, the page refreshes in the background. This is because nginx closes the connection after a certain period of inactivity—not receiving a WebSocket ping. My theory is that browsers stop sending pings once a tab is unfocused, which causes nginx to reap the connection after some time. This is fine and expected, but it causes the frontend to refresh even when the app is inactive. This can cause unnecessary requests to the server despite the user being inactive. We should only attempt to refresh the page once the user focuses the tab again.
liquidev commented 2024-09-02 21:52:37 +02:00 (Migrated from github.com)

Actually, it seems like just sending our own non-WebSocket ping message would work:

By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds. This timeout can be increased with the proxy_read_timeout directive. Alternatively, the proxied server can be configured to periodically send WebSocket ping frames to reset the timeout and check if the connection is still alive.

http://nginx.org/en/docs/http/websocket.html

Actually, it seems like just sending our own non-WebSocket ping message would work: > By default, the connection will be closed if the proxied server does not transmit any data within 60 seconds. This timeout can be increased with the proxy_read_timeout directive. Alternatively, the proxied server can be configured to periodically send WebSocket ping frames to reset the timeout and check if the connection is still alive. http://nginx.org/en/docs/http/websocket.html
liquidev commented 2024-09-02 22:45:03 +02:00 (Migrated from github.com)

Also, it seems that we'll need to raise the timeout a bit in nginx, because Chrome will throttle timers to once per minute if the page isn't active for too long. https://developer.chrome.com/blog/timer-throttling-in-chrome-88

Also, it seems that we'll need to raise the timeout a bit in nginx, because Chrome will throttle timers to once per minute if the page isn't active for too long. https://developer.chrome.com/blog/timer-throttling-in-chrome-88
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: liquidex/rkgk#75
No description provided.