🔄 Fix Upload Progress Events That Stop Firing Partway Through a Large File Because the Browser Switched Transfer Strategy Mid-Upload
A progress bar built on XMLHttpRequest’s upload.onprogress event can climb smoothly for the first chunk of a large file upload and then just stop updating, even though the upload is still actually running in the background and completes successfully moments later – the progress bar simply never finds out. Some browsers and some network conditions cause the underlying transfer to switch buffering or chunking strategy partway through a large body, and progress events that were firing based on bytes-sent-so-far at the application layer can stall out once the browser hands the rest of the body off to a lower-level transfer mechanism that doesn’t report back at the same granularity.
🔎 The Problem
const xhr = new XMLHttpRequest();
xhr.upload.onprogress = (e) => {
const pct = (e.loaded / e.total) * 100;
progressBar.style.width = pct + '%';
// Fires smoothly up to ~40% on a 2GB file upload, then
// nothing - no more progress events at all - until the
// request's own 'load' event fires with the upload
// already fully complete.
};
xhr.open('POST', '/upload');
xhr.send(largeFile);
✅ Fix: Treat the Progress Bar as an Estimate, and Add a Completion-Independent Status Check
- Don’t make the UI depend on onprogress reaching 100% to know the upload finished – listen for the request’s load (and error) event as the actual source of truth for completion, and let onprogress only drive the visual bar as a best-effort estimate that’s allowed to stall without breaking anything else in the flow.
- For uploads large enough that this is a recurring problem, switch to chunked upload (splitting the file into smaller pieces sent as separate requests, each reporting its own completion) instead of a single massive request – this keeps progress reporting granular throughout, because each chunk’s own onprogress and load events are small and reliable instead of riding on one request that can go quiet for an extended stretch.
- If chunking isn’t practical right now, show an indeterminate spinner or a ‘still uploading, this can take a while for large files’ message once progress hasn’t updated for several seconds, rather than leaving a stalled percentage on screen that makes it look like the upload froze when it’s actually still working.
🚨 Why This Is Dangerous
- A user watching a stalled progress bar on a slow connection has no way to tell the difference between ‘still uploading, progress reporting just stopped’ and ‘actually frozen, something’s wrong’ – without a separate heartbeat or status indicator, the natural response is to refresh the page or retry, which can cancel a large upload that was seconds from finishing.
An upload progress event is a courtesy the browser offers while it can, not a guarantee it owes for the entire transfer – plan the UI around the request actually completing, not around the percentage reliably reaching one hundred.

