Stop caching index.html and speed up socket reconnect
Phones offer no easy hard-refresh, so a cached index.html kept serving an old bundle after a deploy (the live feed showed "reconnecting"). index.html and the SPA catch-all now send Cache-Control: no-store, while hashed /assets stay immutable. Also retry the first socket reconnect after 1s (was 2s) and surface the close code in the header so a failure is actionable on a phone.
This commit is contained in:
1 parent
6df44520fa
commit
c63753e592
3 files changed
+33
-6
No files matched your search
+8
-5
@@ -26,7 +26,7 @@ export const getPresets = () => http.get('/presets').then((r) => r.data)
|
||||
export const createPreset = (payload) => http.post('/presets', payload).then((r) => r.data)
|
||||
export const deletePreset = (id) => http.delete(`/presets/${id}`).then((r) => r.data)
|
||||
|
||||
export function openSocket({ onMessage, onOpen, onClose }) {
|
||||
export function openSocket({ onMessage, onOpen, onClose, onError }) {
|
||||
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws'
|
||||
const url = `${proto}://${window.location.host}/api/ws`
|
||||
let socket
|
||||
@@ -36,9 +36,9 @@ export function openSocket({ onMessage, onOpen, onClose }) {
|
||||
|
||||
const schedule = () => {
|
||||
if (closed) return
|
||||
// Back off from 2s up to 30s so a persistently failing socket (e.g. auth)
|
||||
// does not hammer the server, while a brief blip still reconnects fast.
|
||||
const delay = Math.min(2000 * 2 ** attempt, 30000)
|
||||
// Retry at 1s, then back off up to 30s so a persistently failing socket
|
||||
// does not hammer the server while a brief blip recovers immediately.
|
||||
const delay = Math.min(1000 * 2 ** attempt, 30000)
|
||||
attempt += 1
|
||||
retryTimer = setTimeout(connect, delay)
|
||||
}
|
||||
@@ -51,8 +51,11 @@ export function openSocket({ onMessage, onOpen, onClose }) {
|
||||
onOpen?.()
|
||||
}
|
||||
socket.onmessage = (event) => onMessage?.(JSON.parse(event.data))
|
||||
socket.onclose = () => {
|
||||
socket.onclose = (event) => {
|
||||
onClose?.()
|
||||
// 1008 = policy violation (token rejected); 1006 = abnormal close, which
|
||||
// is what an auth/proxy rejection looks like to the browser.
|
||||
onError?.(event.code, event.reason)
|
||||
schedule()
|
||||
}
|
||||
socket.onerror = () => socket.close()
|
||||
|
||||
Reference in new issue
Block a user