From 7a9dcfb6ec52134d48b6a604623334503c0073f4 Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 7 Mar 2024 14:34:10 -0500 Subject: [PATCH] use requestAnimationFrame for cleaner progress bar updates --- static/js/upload.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/static/js/upload.js b/static/js/upload.js index 9ec6e79..31dc08c 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -31,6 +31,7 @@ let progressSize; let progressRate; let progressEta; let progressBar; +let animationID = null; window.addEventListener('beforeunload', (event) => { if (socket && socket.readyState !== 3) { @@ -291,7 +292,9 @@ function sendData() { if (timestamps.length > SAMPLE_WINDOW) { timestamps.shift(); } } - updateProgress(); + if (animationID === null) { + animationID = requestAnimationFrame(updateProgress); + } } else { fileIndex += 1; byteIndex = 0; @@ -300,6 +303,8 @@ function sendData() { } function updateProgress() { + animationID = null; + let percentage; if (totalBytes === 0) { percentage = "0%";