From 66a873b3c2f2eb235a46d69802854c3431720106 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Sat, 20 Jul 2024 21:48:43 +0100 Subject: [PATCH] fix: prevent browser from caching audio Add a random query parameter to the end of the track URL to prevent the browser from caching the audio file, forcing it to fetch the latest track --- web/script.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/script.js b/web/script.js index f8f4a7a..7e425b5 100644 --- a/web/script.js +++ b/web/script.js @@ -5,7 +5,8 @@ let currentAudio; let volume = 1; function playAudio() { - currentAudio = new Audio("/current.mp3"); + // add a random query parameter at the end to prevent browser caching + currentAudio = new Audio(`/current.mp3?t=${Date.now()}`); currentAudio.onplay = () => { isPlaying = true; playBtn.innerText = "pause";