Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Ajax

Ajax: Fix Upload Progress Events That Stop Firing Partway Through a Large File Because the Browser Switched Transfer Strategy Mid-Upload

- 23.10.26 - ErcanOPAK

🔄 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.

— Frontend Engineer

Related posts:

Ajax: Know When to Use GET vs POST Requests

Ajax: Know When to Use GET vs POST Requests

Ajax: Use Fetch API Instead of XMLHttpRequest for Clean Async Requests

Ajax: Use Fetch API Instead of XMLHttpRequest for Clean Async Requests

AJAX: Use URLSearchParams to Build Query Strings Cleanly

AJAX: Use URLSearchParams to Build Query Strings Cleanly

Views: 9

Post navigation

Git: Fix an Interactive Rebase That Reorders Commits Cleanly but Silently Leaves a Merge Conflict Marker Committed Into a File
HTML5: Fix a Form’s novalidate Attribute Silently Disabling Built-In Validation for Every Field Instead of Just the One It Was Meant For

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com