How Do You Handle Stale Frontend Bundles During Breaking API Changes?
Asked by
MellowPine47
I ran into a strange issue where an old browser tab was still using a previous frontend build after deployment. An API change was introduced, and requests from that stale bundle started failing. For situations like this, is it better to keep the API backward-compatible for some period, or should the application detect the mismatch and force a refresh when a breaking change is deployed?
Answers
For a simple app, catch the failure and trigger a refresh. Itโs quick and usually solves the problem, although you should avoid creating a reload loop if the new build still has an issue.
Reply to this answer
Version the frontend assets so browsers and CDNs donโt keep serving stale files. Content-hashed filenames, such as those generated by Vite and similar build tools, are a good cache-busting strategy. For the API itself, backward compatibility is preferable; if that isnโt practical, expose a new API version such as /v2 rather than breaking existing clients.
Reply to this answer
A smoother option is to have every API response include the current frontend or deployment version in a header. The frontend can compare that value with the build version embedded at compile time. If they differ, show a message saying a new version is available and offer a refresh, instead of letting an unrelated API request fail unexpectedly.
Reply to this answer
The usual approach is to keep normal API changes backward-compatible and deploy backend changes before the frontend. For genuinely breaking changes, schedule the deployment and monitor which frontend build numbers are still active. Once the incompatible build is no longer being used, deploy the API change. You can include the build number in frontend telemetry through tools such as Application Insights or OpenTelemetry.
Reply to this answer
Add your answer
Answers are reviewed before publication.
MellowPine47: That sounds less disruptive than forcing a reload immediately, especially for users who might be in the middle of entering data.